Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video downloader #21

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
*/

var ResponGdm = false;
var interruptDownloads = true;
var InterruptDownloads = true;
var PortSet = "";
var CustomPort = false;
var DownloadVideo = false;

load_conf ();

Expand All @@ -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: ['<all_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: ['<all_urls>']}, ['responseHeaders']);
});

function WebContent (content) {
Expand All @@ -59,7 +69,7 @@ function WebContent (content) {
}

chrome.downloads.onCreated.addListener (function (downloadItem) {
if (!interruptDownloads || ResponGdm) {
if (!InterruptDownloads || ResponGdm) {
return;
}
setTimeout (()=> {
Expand All @@ -69,7 +79,7 @@ chrome.downloads.onCreated.addListener (function (downloadItem) {
});

chrome.downloads.onDeterminingFilename.addListener (function (downloadItem) {
if (!interruptDownloads || ResponGdm) {
if (!InterruptDownloads || ResponGdm) {
return;
}
setTimeout (()=> {
Expand Down Expand Up @@ -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 ();
Expand All @@ -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);
Expand All @@ -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 ();
Expand All @@ -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 () {});
Expand All @@ -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"});
Expand Down
4 changes: 2 additions & 2 deletions content-script.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
11 changes: 2 additions & 9 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -47,7 +39,8 @@
"storage",
"tabs",
"webRequest",
"activeTab"
"activeTab",
"scripting"
],
"host_permissions": ["<all_urls>"]
}
7 changes: 6 additions & 1 deletion popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</div>
</div>
<br>
<div class="tittle">Custom Port</div>
<div class="tittle">Multimedia Download</div>
<div id="keyboard">
<div class="f_key">
<div class="keycap">Ctrl</div>
Expand All @@ -62,6 +62,11 @@
<label class="switch">
<input type="checkbox" id="interrupt-download">
<span class="slider"></span>
</label>
<div class="tittle">Multimedia Download</div>
<label class="switch">
<input type="checkbox" id="video-download">
<span class="slider"></span>
</label>
<div class="tittle">Costum Port</div>
<label class="switch">
Expand Down
12 changes: 11 additions & 1 deletion popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,25 @@

let PortInput = $('#port-input');
let DownloadIntrupt = $('#interrupt-download');
let DownloadVideo = $('#video-download');
let PortCustom = $('#port-custom');

chrome.runtime.sendMessage({ extensionId: "interuptopen" }).catch(function() {});
chrome.runtime.sendMessage({ extensionId: "customopen" }).catch(function() {});
chrome.runtime.sendMessage({ extensionId: "portopen" }).catch(function() {});
chrome.runtime.sendMessage({ extensionId: "videoopen" }).catch(function() {});

DownloadIntrupt.on("change", dwinterupt);
PortCustom.on("change", customchecked);
DownloadVideo.on("change", videocase);
PortInput.on("change paste keyup", portinput);

function dwinterupt () {
chrome.runtime.sendMessage({ message: DownloadIntrupt.prop ('checked'), extensionId: "interuptchecked" }).catch(function() {});
}
function videocase () {
chrome.runtime.sendMessage({ message: DownloadVideo.prop ('checked'), extensionId: "videochecked" }).catch(function() {});
}

function customchecked () {
chrome.runtime.sendMessage({ message: PortCustom.prop ('checked'), extensionId: "customchecked" }).catch(function() {});
Expand All @@ -47,10 +54,12 @@ chrome.runtime.onMessage.addListener((request, callback) => {
if (request.extensionId == "Ctrl+Shift+Y") {
DownloadIntrupt.prop('checked', request.message);
} else if (request.extensionId == "Ctrl+Shift+E") {
PortCustom.prop('checked', request.message);
DownloadVideo.prop('checked', request.message);
hide_popin ();
} else if (request.extensionId == "popintrup") {
DownloadIntrupt.prop('checked', request.message);
} else if (request.extensionId == "popvideo") {
DownloadVideo.prop('checked', request.message);
} else if (request.extensionId == "popcust") {
PortCustom.prop('checked', request.message);
hide_popin ();
Expand All @@ -70,4 +79,5 @@ function hide_popin () {
setInterval(function () {
chrome.runtime.sendMessage({ extensionId: "interuptopen" }).catch(function() {});
chrome.runtime.sendMessage({ extensionId: "customopen" }).catch(function() {});
chrome.runtime.sendMessage({ extensionId: "videoopen" }).catch(function() {});
}, 1000);