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
This commit is contained in:
parent
b48b682c2e
commit
1a12fc0c99
|
|
@ -29,17 +29,15 @@ function sendVideoUrlToMetubeAndSwitchTab(videoUrl, metubeUrl, tab) {
|
||||||
if (res.ok === true && res.status === 200) {
|
if (res.ok === true && res.status === 200) {
|
||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
// todo fix it
|
console.log("error :: code " + res.status);
|
||||||
alert("error :: code " + res.status);
|
|
||||||
}).then(function(result) {
|
}).then(function(result) {
|
||||||
if (result.status === "ok") {
|
if (result.status === "ok") {
|
||||||
openTab(metubeUrl, tab);
|
openTab(metubeUrl, tab);
|
||||||
} else {
|
} else {
|
||||||
// todo fix it
|
console.log("error :: ", result );
|
||||||
alert("error :: " + json);
|
|
||||||
}
|
}
|
||||||
}).catch(function(res) {
|
}).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.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 === "") {
|
if (data === undefined || !data.hasOwnProperty('metube') || data.metube === "") {
|
||||||
openTab(chrome.runtime.getURL('options.html'), tab);
|
openTab(chrome.runtime.getURL('options.html'), tab);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
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({
|
chrome.tabs.query({
|
||||||
active: true,
|
active: true,
|
||||||
lastFocusedWindow: true
|
lastFocusedWindow: true
|
||||||
}, function(tabs) {
|
}, function(tabs) {
|
||||||
// use this tab to get the youtube video URL
|
// use this tab to get the youtube video URL
|
||||||
let videoUrl = tabs[0].url;
|
let videoUrl = tabs[0].url;
|
||||||
if (data.sendOnClick) {
|
|
||||||
sendVideoUrlToMetubeAndSwitchTab(videoUrl, data.metube, tab);
|
sendVideoUrlToMetubeAndSwitchTab(videoUrl, data.metube, tab);
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.log("Going to Metube URL...");
|
|
||||||
openTab(data.metube, tab);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
console.log("Unknown clickBehavior value: " + data.clickBehavior);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,10 @@
|
||||||
<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>
|
<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">
|
<h4>Left-click on extension icon behavior</h4>
|
||||||
|
<input type="radio" name="click-behavior" id="do-nothing" value="do-nothing"><label for="do-nothing">Do Nothing</label><br>
|
||||||
|
<input type="radio" name="click-behavior" id="go-to-metube" value="go-to-metube" checked><label for="go-to-metube">Go to MeTube URL</label><br>
|
||||||
|
<input type="radio" name="click-behavior" id="send-current-url-and-switch" value="send-current-url-and-switch"><label for="send-current-url-and-switch">Send current tab URL to MeTube and switch to MeTube</label><br>
|
||||||
<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/*
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,13 @@ async function saveOptions() {
|
||||||
|
|
||||||
let sites = document.getElementById("additional").value;
|
let sites = document.getElementById("additional").value;
|
||||||
|
|
||||||
let sendOnClick = document.getElementById("send-on-click").checked;
|
let clickBehavior = document.querySelector('input[name="click-behavior"]:checked').value;
|
||||||
|
|
||||||
chrome.storage.sync.set({ "metube": url, "sites": sites, "sendOnClick": sendOnClick}, function () {
|
chrome.storage.sync.set({
|
||||||
|
"metube": url,
|
||||||
|
"sites": sites,
|
||||||
|
"clickBehavior": clickBehavior
|
||||||
|
}, function () {
|
||||||
document.getElementById("saved").classList.remove('hidden');
|
document.getElementById("saved").classList.remove('hidden');
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
|
@ -41,7 +45,11 @@ async function saveOptions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function restoreOptions() {
|
async function restoreOptions() {
|
||||||
chrome.storage.sync.get(['metube', 'sites', 'sendOnClick'], function (data) {
|
chrome.storage.sync.get([
|
||||||
|
'metube',
|
||||||
|
'sites',
|
||||||
|
'clickBehavior'
|
||||||
|
], function (data) {
|
||||||
if (data.metube != undefined) {
|
if (data.metube != undefined) {
|
||||||
document.getElementById("metube").value = data.metube;
|
document.getElementById("metube").value = data.metube;
|
||||||
}
|
}
|
||||||
|
|
@ -49,11 +57,9 @@ 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(data.clickBehavior).checked = true;
|
||||||
document.getElementById("send-on-click").checked = true;
|
})
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function splitLines(t) { return t.split(/\r\n|\r|\n/); }
|
function splitLines(t) { return t.split(/\r\n|\r|\n/); }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue