Added option for silently sending current tab URL to MeTube via extension icon click (no tab switch)
Added the new option as another radio button that user may select when deciding the extention icon click behavior
This commit is contained in:
parent
1a12fc0c99
commit
7a104e2e8c
|
|
@ -13,7 +13,7 @@ chrome.runtime.onInstalled.addListener(function() {
|
|||
});
|
||||
});
|
||||
|
||||
function sendVideoUrlToMetubeAndSwitchTab(videoUrl, metubeUrl, tab) {
|
||||
function sendVideoUrlToMetube(videoUrl, metubeUrl, callback) {
|
||||
console.log("Sending videoUrl=" + videoUrl + " to metubeUrl=" + metubeUrl);
|
||||
fetch(metubeUrl + "/add", {
|
||||
method: 'POST',
|
||||
|
|
@ -29,15 +29,19 @@ function sendVideoUrlToMetubeAndSwitchTab(videoUrl, metubeUrl, tab) {
|
|||
if (res.ok === true && res.status === 200) {
|
||||
return res.json();
|
||||
}
|
||||
console.log("error :: code " + res.status);
|
||||
console.log("error :: code" + res.status);
|
||||
}).then(function(result) {
|
||||
if (result.status === "ok") {
|
||||
openTab(metubeUrl, tab);
|
||||
} else {
|
||||
if (result.status !== "ok") {
|
||||
console.log("error :: ", result );
|
||||
if (result.msg.includes('URLError')) {
|
||||
// Go straight to catch block and skip the callback
|
||||
throw new Error('Error when adding URL to MyTube');
|
||||
}
|
||||
}
|
||||
}).catch(function(res) {
|
||||
console.log("Final catch - error :: " + res);
|
||||
}).then(function() {
|
||||
typeof callback === 'function' && callback();
|
||||
}).catch(function(e) {
|
||||
console.log("Ran into an error :: ", e);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +51,9 @@ chrome.contextMenus.onClicked.addListener(function(item, tab) {
|
|||
openTab(chrome.runtime.getURL('options.html'), tab);
|
||||
return
|
||||
}
|
||||
sendVideoUrlToMetubeAndSwitchTab(item.linkUrl, data.metube, tab);
|
||||
sendVideoUrlToMetube(item.linkUrl, data.metube, function() {
|
||||
openTab(data.metube, tab);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -62,6 +68,15 @@ chrome.action.onClicked.addListener(function(tab) {
|
|||
} else if (data.clickBehavior == 'go-to-metube') {
|
||||
console.log("Going to Metube URL...");
|
||||
openTab(data.metube, tab);
|
||||
} else if (data.clickBehavior == 'send-current-url') {
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
lastFocusedWindow: true
|
||||
}, function(tabs) {
|
||||
// use this tab to get the youtube video URL
|
||||
let videoUrl = tabs[0].url;
|
||||
sendVideoUrlToMetube(videoUrl, data.metube);
|
||||
});
|
||||
} else if (data.clickBehavior == 'send-current-url-and-switch') {
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
|
|
@ -69,7 +84,9 @@ chrome.action.onClicked.addListener(function(tab) {
|
|||
}, function(tabs) {
|
||||
// use this tab to get the youtube video URL
|
||||
let videoUrl = tabs[0].url;
|
||||
sendVideoUrlToMetubeAndSwitchTab(videoUrl, data.metube, tab);
|
||||
sendVideoUrlToMetube(videoUrl, data.metube, function() {
|
||||
openTab(data.metube, tab);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log("Unknown clickBehavior value: " + data.clickBehavior);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
<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" value="send-current-url"><label for="send-current-url">Send current tab URL to MeTube (no tab switch)</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>
|
||||
<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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue