Added capability for clicking on extension icon to trigger video download

Added an option to allow left-clicking on extension icon to allow the current tab URL to be sent to MeTube.
This new behaviour is available by opting in via a checkbox from the extension's options page.
This commit is contained in:
Akash Vacher 2022-10-01 01:24:36 -07:00
parent 21cfe5e127
commit b48b682c2e
3 changed files with 28 additions and 9 deletions

View File

@ -54,13 +54,25 @@ chrome.contextMenus.onClicked.addListener(function(item, tab) {
}); });
chrome.action.onClicked.addListener(function(tab) { chrome.action.onClicked.addListener(function(tab) {
chrome.storage.sync.get(['metube'], function(data) { chrome.storage.sync.get(['metube', 'sendOnClick'], function(data) {
if (data === undefined || !data.hasOwnProperty('metube') || data.metube === "") { if (data === undefined || !data.hasOwnProperty('metube') || data.metube === "") {
openTab(chrome.runtime.getURL('options.html'), tab); openTab(chrome.runtime.getURL('options.html'), tab);
return 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) {
sendVideoUrlToMetubeAndSwitchTab(videoUrl, data.metube, tab);
}
else {
console.log("Going to Metube URL...");
openTab(data.metube, tab); openTab(data.metube, tab);
}
});
}); });
}); });

View File

@ -32,6 +32,8 @@
<form id="form"> <form id="form">
<h3>Settings</h3> <h3>Settings</h3>
<label for="metube">Url of MeTube</label><input type="url" placeholder="http://0.0.0.0:8081/" name="metube" id="metube"> <label for="metube">Url of MeTube</label><input type="url" placeholder="http://0.0.0.0:8081/" name="metube" id="metube">
<br>
<label for="send-on-click">Enable left-click on extension icon to send current page URL to Metube</label><input type="checkbox" name="send-on-click" id="send-on-click">
<h3>Additional sites</h3> <h3>Additional sites</h3>
<p>Youtube-dl support <a href="https://github.com/ytdl-org/youtube-dl/blob/master/docs/supportedsites.md" target="_blank">many another sites</a> 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</p> <p>Youtube-dl support <a href="https://github.com/ytdl-org/youtube-dl/blob/master/docs/supportedsites.md" target="_blank">many another sites</a> 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</p>
<p><textarea name="additional" id="additional" placeholder="https://vimeo.com/* <p><textarea name="additional" id="additional" placeholder="https://vimeo.com/*

View File

@ -7,7 +7,9 @@ async function saveOptions() {
let sites = document.getElementById("additional").value; let sites = document.getElementById("additional").value;
chrome.storage.sync.set({ "metube": url, "sites": sites }, function () { let sendOnClick = document.getElementById("send-on-click").checked;
chrome.storage.sync.set({ "metube": url, "sites": sites, "sendOnClick": sendOnClick}, function () {
document.getElementById("saved").classList.remove('hidden'); document.getElementById("saved").classList.remove('hidden');
setTimeout(function () { setTimeout(function () {
@ -39,7 +41,7 @@ async function saveOptions() {
} }
async function restoreOptions() { async function restoreOptions() {
chrome.storage.sync.get(['metube', 'sites'], function (data) { chrome.storage.sync.get(['metube', 'sites', 'sendOnClick'], function (data) {
if (data.metube != undefined) { if (data.metube != undefined) {
document.getElementById("metube").value = data.metube; document.getElementById("metube").value = data.metube;
} }
@ -47,7 +49,10 @@ async function restoreOptions() {
if (data.sites != undefined) { if (data.sites != undefined) {
document.getElementById("additional").value = data.sites; document.getElementById("additional").value = data.sites;
} }
// document.getElementById("send-on-click").checked = true;
if (data.sendOnClick) {
document.getElementById("send-on-click").checked = true;
}
}); });
} }