From 1a12fc0c99a27194a27ae7838536110f5c9a97de Mon Sep 17 00:00:00 2001 From: Akash Vacher Date: Sat, 1 Oct 2022 11:03:54 -0700 Subject: [PATCH 1/8] Added customisable click-behavior for left-click to extension icon The behavior can be customised by selecting the appropriate radio button on the extension's options page --- src/background.js | 39 ++++++++++++++++++++------------------- src/options.html | 5 ++++- src/options.js | 22 ++++++++++++++-------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/background.js b/src/background.js index 3d4a5cf..19f5f60 100644 --- a/src/background.js +++ b/src/background.js @@ -29,17 +29,15 @@ function sendVideoUrlToMetubeAndSwitchTab(videoUrl, metubeUrl, tab) { if (res.ok === true && res.status === 200) { return res.json(); } - // todo fix it - alert("error :: code " + res.status); + console.log("error :: code " + res.status); }).then(function(result) { if (result.status === "ok") { openTab(metubeUrl, tab); } else { - // todo fix it - alert("error :: " + json); + console.log("error :: ", result ); } }).catch(function(res) { - alert("error :: " + res); + console.log("Final catch - error :: " + res); }); } @@ -54,25 +52,28 @@ chrome.contextMenus.onClicked.addListener(function(item, tab) { }); chrome.action.onClicked.addListener(function(tab) { - chrome.storage.sync.get(['metube', 'sendOnClick'], function(data) { + chrome.storage.sync.get(['metube', 'clickBehavior'], function(data) { if (data === undefined || !data.hasOwnProperty('metube') || data.metube === "") { openTab(chrome.runtime.getURL('options.html'), tab); return } - chrome.tabs.query({ - active: true, - lastFocusedWindow: true - }, function(tabs) { - // use this tab to get the youtube video URL - let videoUrl = tabs[0].url; - if (data.sendOnClick) { + if (data.clickBehavior == 'do-nothing') { + return + } else if (data.clickBehavior == 'go-to-metube') { + console.log("Going to Metube URL..."); + openTab(data.metube, tab); + } else if (data.clickBehavior == 'send-current-url-and-switch') { + chrome.tabs.query({ + active: true, + lastFocusedWindow: true + }, function(tabs) { + // use this tab to get the youtube video URL + let videoUrl = tabs[0].url; sendVideoUrlToMetubeAndSwitchTab(videoUrl, data.metube, tab); - } - else { - console.log("Going to Metube URL..."); - openTab(data.metube, tab); - } - }); + }); + } else { + console.log("Unknown clickBehavior value: " + data.clickBehavior); + } }); }); diff --git a/src/options.html b/src/options.html index 97c2e75..6b4f7d7 100644 --- a/src/options.html +++ b/src/options.html @@ -33,7 +33,10 @@

Settings


- +

Left-click on extension icon behavior

+
+
+

Additional sites

Youtube-dl support many another sites except youtube. You can add mask url's of this sites in textfield bellow but it can affect performance and we have not tested them support