diff --git a/background.js b/background.js index 678c91c..f83ece4 100644 --- a/background.js +++ b/background.js @@ -20,9 +20,10 @@ */ var ResponGdm = false; -var interruptDownloads = true; +var InterruptDownloads = true; var PortSet = ""; var CustomPort = false; +var DownloadVideo = false; load_conf (); @@ -36,11 +37,20 @@ setInterval (function () { }, 2000); chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab)=> { - if (changeInfo.status == 'loading') { - chrome.webRequest.onResponseStarted.removeListener (WebContent); - chrome.tabs.sendMessage(tabId, {message: 'gdmclean'}).then (function () {}).catch(function() {}); + if (DownloadVideo) { + if (changeInfo.status == 'loading') { + chrome.webRequest.onResponseStarted.removeListener (WebContent); + chrome.tabs.sendMessage(tabId, {message: 'gdmclean'}).then (function () {}).catch(function() {}); + } + chrome.webRequest.onResponseStarted.addListener (WebContent, {urls: ['']}, ['responseHeaders']); + if (tab.url?.startsWith("chrome://")) { + return undefined; + } + if (changeInfo.status === "complete") { + chrome.scripting.executeScript({target: {tabId: tabId}, files: ['content-script.js'],}); + chrome.scripting.insertCSS({target: { tabId: tabId }, files: ["content-script.css"]}); + } } - chrome.webRequest.onResponseStarted.addListener (WebContent, {urls: ['']}, ['responseHeaders']); }); function WebContent (content) { @@ -59,7 +69,7 @@ function WebContent (content) { } chrome.downloads.onCreated.addListener (function (downloadItem) { - if (!interruptDownloads || ResponGdm) { + if (!InterruptDownloads || ResponGdm) { return; } setTimeout (()=> { @@ -69,7 +79,7 @@ chrome.downloads.onCreated.addListener (function (downloadItem) { }); chrome.downloads.onDeterminingFilename.addListener (function (downloadItem) { - if (!interruptDownloads || ResponGdm) { + if (!InterruptDownloads || ResponGdm) { return; } setTimeout (()=> { @@ -114,7 +124,8 @@ async function chromeStorageGetter (key) { } async function load_conf () { - interruptDownloads = await chromeStorageGetter ('interrupt-download'); + InterruptDownloads = await chromeStorageGetter ('interrupt-download'); + DownloadVideo = await chromeStorageGetter ('video-download'); CustomPort = await chromeStorageGetter ('port-custom'); PortSet = await chromeStorageGetter ('port-input'); icon_load (); @@ -124,6 +135,10 @@ async function setPortCustom (interrupt) { await SavetoStorage('port-custom', interrupt); } +async function setVideoMenu (download) { + await SavetoStorage('video-download', download); +} + async function setPortInput (interrupt) { if (CustomPort) { await SavetoStorage('port-input', interrupt); @@ -142,21 +157,26 @@ async function SavetoStorage(key, value) { chrome.commands.onCommand.addListener((command) => { if (command == "Ctrl+Shift+Y") { - setInterruptDownload (!interruptDownloads); + setInterruptDownload (!InterruptDownloads); load_conf (); } else if (command == "Ctrl+Shift+E") { - setPortCustom (!CustomPort); + setVideoMenu (!DownloadVideo); load_conf (); } }); chrome.runtime.onMessage.addListener((request, sender, callback) => { if (request.extensionId == "interuptopen") { - chrome.runtime.sendMessage({ message: interruptDownloads, extensionId: "popintrup" }).catch(function() {}); + chrome.runtime.sendMessage({ message: InterruptDownloads, extensionId: "popintrup" }).catch(function() {}); } else if (request.extensionId == "customopen") { chrome.runtime.sendMessage({ message: CustomPort, extensionId: "popcust" }).catch(function() {}); } else if (request.extensionId == "portopen") { chrome.runtime.sendMessage({ message: PortSet, extensionId: "popport" }).catch(function() {}); + } else if (request.extensionId == "videoopen") { + chrome.runtime.sendMessage({ message: DownloadVideo, extensionId: "popvideo" }).catch(function() {}); + } else if (request.extensionId == "videochecked") { + setVideoMenu (request.message); + load_conf (); } else if (request.extensionId == "interuptchecked") { setInterruptDownload (request.message); load_conf (); @@ -167,7 +187,7 @@ chrome.runtime.onMessage.addListener((request, sender, callback) => { setPortInput (request.message); load_conf (); } else if (request.extensionId == "gdmurl") { - if (!interruptDownloads || ResponGdm) { + if (!InterruptDownloads || ResponGdm) { return; } fetch (get_host (), { method: 'post', body: request.message }).then (function (r) { return r.text (); }).catch (function () {}); @@ -183,7 +203,7 @@ get_host = function () { } icon_load = function () { - if (interruptDownloads && !ResponGdm) { + if (InterruptDownloads && !ResponGdm) { chrome.action.setIcon({path: "./icons/icon_32.png"}); } else { chrome.action.setIcon({path: "./icons/icon_disabled_32.png"}); diff --git a/content-script.js b/content-script.js index 541f1cf..ed6c50f 100644 --- a/content-script.js +++ b/content-script.js @@ -1,5 +1,5 @@ -let videourl = ''; -let audiourl = ''; +var videourl = ''; +var audiourl = ''; var input = document.createElement('input'); input.id = 'menu-open'; input.className = 'menu-open'; diff --git a/manifest.json b/manifest.json index 7520e7c..3cc3373 100644 --- a/manifest.json +++ b/manifest.json @@ -13,14 +13,6 @@ "background": { "service_worker": "background.js" }, - "content_scripts": [ - { - "matches": [ "http://*/*", "https://*/*", "ftp://*/*", "file:///*" ], - "all_frames": false, - "js": ["content-script.js"], - "css": ["content-script.css"] - } - ], "commands": { "Ctrl+Shift+Y": { "suggested_key": { @@ -47,7 +39,8 @@ "storage", "tabs", "webRequest", - "activeTab" + "activeTab", + "scripting" ], "host_permissions": [""] } \ No newline at end of file diff --git a/popup/popup.html b/popup/popup.html index c3b34bc..a65eaa2 100644 --- a/popup/popup.html +++ b/popup/popup.html @@ -47,7 +47,7 @@
-
Custom Port
+
Multimedia Download
Ctrl
@@ -62,6 +62,11 @@ +
Multimedia Download
+
Costum Port