From cd93313cfc3a26a0cd113466567f55dc4cd47a17 Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Fri, 18 Dec 2020 18:34:30 -0500 Subject: [PATCH] Updated Chrome/Firefox extension to 0.4 --- chrome-extension/background.js | 20 -------------- chrome-extension/manifest.json | 9 ++++-- chrome-extension/popup.html | 35 ++++++++++++++++++++++++ chrome-extension/popup.js | 50 ++++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 23 deletions(-) delete mode 100644 chrome-extension/background.js create mode 100644 chrome-extension/popup.html create mode 100644 chrome-extension/popup.js diff --git a/chrome-extension/background.js b/chrome-extension/background.js deleted file mode 100644 index 4785a23..0000000 --- a/chrome-extension/background.js +++ /dev/null @@ -1,20 +0,0 @@ -// background.js - -// Called when the user clicks on the browser action. -chrome.browserAction.onClicked.addListener(function(tab) { - // get the frontend_url - chrome.storage.sync.get({ - frontend_url: 'http://localhost', - audio_only: false - }, function(items) { - chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { - var activeTab = tabs[0]; - var url = activeTab.url; - if (url.includes('youtube.com')) { - var new_url = items.frontend_url + '/#/home;url=' + encodeURIComponent(url) + ';audioOnly=' + items.audio_only; - chrome.tabs.create({ url: new_url }); - } - }); - }); - -}); \ No newline at end of file diff --git a/chrome-extension/manifest.json b/chrome-extension/manifest.json index 1ecf992..f5f4f79 100644 --- a/chrome-extension/manifest.json +++ b/chrome-extension/manifest.json @@ -1,17 +1,20 @@ { "manifest_version": 2, "name": "YoutubeDL-Material", - "version": "0.3", + "version": "0.4", "description": "The Official Firefox & Chrome Extension of YoutubeDL-Material, an open-source and self-hosted YouTube downloader.", "background": { "scripts": ["background.js"] }, "browser_action": { - "default_icon": "favicon.png" + "default_icon": "favicon.png", + "default_popup": "popup.html", + "default_title": "YoutubeDL-Material" }, "permissions": [ "tabs", - "storage" + "storage", + "contextMenus" ], "options_ui": { "page": "options.html", diff --git a/chrome-extension/popup.html b/chrome-extension/popup.html new file mode 100644 index 0000000..467925c --- /dev/null +++ b/chrome-extension/popup.html @@ -0,0 +1,35 @@ + + + + + + + + + + + + + +
+
+
+ +
+ +
+ +
+ +
+
+
+
+ + + + + \ No newline at end of file diff --git a/chrome-extension/popup.js b/chrome-extension/popup.js new file mode 100644 index 0000000..9e48758 --- /dev/null +++ b/chrome-extension/popup.js @@ -0,0 +1,50 @@ +function audioOnlyClicked() { + console.log('audio only clicked'); + var audio_only = document.getElementById("audio_only").checked; + + // save state + + chrome.storage.sync.set({ + audio_only: audio_only + }, function() {}); +} + +function downloadVideo() { + var input_url = document.getElementById("url_input").value + // get the frontend_url + chrome.storage.sync.get({ + frontend_url: 'http://localhost', + audio_only: false + }, function(items) { + var download_url = items.frontend_url + '/#/home;url=' + encodeURIComponent(input_url) + ';audioOnly=' + items.audio_only; + chrome.tabs.create({ url: download_url }); + }); +} + +function loadInputs() { + // load audio-only input + chrome.storage.sync.get({ + frontend_url: 'http://localhost', + audio_only: false + }, function(items) { + document.getElementById("audio_only").checked = items.audio_only; + }); + + // load url input + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + var activeTab = tabs[0]; + var current_url = activeTab.url; + console.log(current_url); + if (current_url && current_url.includes('youtube.com')) { + document.getElementById("url_input").value = current_url; + } + }); +} + +document.getElementById('download').addEventListener('click', + downloadVideo); + +document.getElementById('audio_only').addEventListener('click', + audioOnlyClicked); + +document.addEventListener('DOMContentLoaded', loadInputs);