v1.5
This commit is contained in:
parent
da85f9ea90
commit
7e261eb367
|
|
@ -13,7 +13,7 @@ chrome.runtime.onInstalled.addListener(function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function sendVideoUrlToMetube(videoUrl, metubeUrl, callback) {
|
function sendVideoUrlToMetube(videoUrl, metubeUrl, format, callback) {
|
||||||
console.log("Sending videoUrl=" + videoUrl + " to metubeUrl=" + metubeUrl);
|
console.log("Sending videoUrl=" + videoUrl + " to metubeUrl=" + metubeUrl);
|
||||||
|
|
||||||
if (typeof callback !== 'function') {
|
if (typeof callback !== 'function') {
|
||||||
|
|
@ -29,6 +29,7 @@ function sendVideoUrlToMetube(videoUrl, metubeUrl, callback) {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
"quality": "best",
|
"quality": "best",
|
||||||
|
"format": format,
|
||||||
"url": videoUrl
|
"url": videoUrl
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -42,7 +43,7 @@ function sendVideoUrlToMetube(videoUrl, metubeUrl, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.contextMenus.onClicked.addListener(function (item, tab) {
|
chrome.contextMenus.onClicked.addListener(function (item, tab) {
|
||||||
chrome.storage.sync.get(['metube', 'contextMenuClickBehavior'], function (data) {
|
chrome.storage.sync.get(['metube', 'contextMenuClickBehavior', 'defaultFormat'], 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
|
||||||
|
|
@ -50,7 +51,7 @@ chrome.contextMenus.onClicked.addListener(function (item, tab) {
|
||||||
|
|
||||||
let needToSwitch = (data.contextMenuClickBehavior === 'context-menu-send-current-url-and-switch');
|
let needToSwitch = (data.contextMenuClickBehavior === 'context-menu-send-current-url-and-switch');
|
||||||
|
|
||||||
sendVideoUrlToMetube(item.linkUrl, data.metube, function () {
|
sendVideoUrlToMetube(item.linkUrl, data.metube, data.defaultFormat, function () {
|
||||||
if (needToSwitch) {
|
if (needToSwitch) {
|
||||||
openTab(data.metube, tab);
|
openTab(data.metube, tab);
|
||||||
}
|
}
|
||||||
|
|
@ -59,7 +60,7 @@ chrome.contextMenus.onClicked.addListener(function (item, tab) {
|
||||||
});
|
});
|
||||||
|
|
||||||
chrome.action.onClicked.addListener(function (tab) {
|
chrome.action.onClicked.addListener(function (tab) {
|
||||||
chrome.storage.sync.get(['metube', 'clickBehavior'], function (data) {
|
chrome.storage.sync.get(['metube', 'clickBehavior', 'defaultFormat'], 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
|
||||||
|
|
@ -78,7 +79,7 @@ chrome.action.onClicked.addListener(function (tab) {
|
||||||
}, 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;
|
||||||
sendVideoUrlToMetube(videoUrl, data.metube, function () {
|
sendVideoUrlToMetube(videoUrl, data.metube, data.defaultFormat, function () {
|
||||||
if (!needToSwitch) {
|
if (!needToSwitch) {
|
||||||
openTab(data.metube, tab);
|
openTab(data.metube, tab);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "MeTube Downloader",
|
"name": "MeTube Downloader",
|
||||||
"description": "Use the context menu to send video into MeTube application",
|
"description": "Use the context menu to send video into MeTube application",
|
||||||
"version": "1.4",
|
"version": "1.5",
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"permissions": ["contextMenus", "storage", "tabs"],
|
"permissions": ["contextMenus", "storage", "tabs"],
|
||||||
"background": {
|
"background": {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,18 @@
|
||||||
<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>
|
<br><br>
|
||||||
|
<label for="default_format">Video format:</label>
|
||||||
|
|
||||||
|
<select name="default_format" id="default_format">
|
||||||
|
<option value="any">Any</option>
|
||||||
|
<option value="mp4">MP4</option>
|
||||||
|
<option value="m4a">M4A</option>
|
||||||
|
<option value="mp3">MP3</option>
|
||||||
|
<option value="opus">OPUS</option>
|
||||||
|
<option value="wav">WAV</option>
|
||||||
|
<option value="thumbnail">Thumbnail</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
<h4>When you left-click on the extension icon, you'd like it to:</h4>
|
<h4>When you left-click on the extension icon, you'd like it to:</h4>
|
||||||
<input type="radio" name="click-behavior" id="go-to-metube" value="go-to-metube"><label for="go-to-metube">Go to MeTube URL</label><br>
|
<input type="radio" name="click-behavior" id="go-to-metube" value="go-to-metube"><label for="go-to-metube">Go to MeTube URL</label><br>
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,14 @@ async function saveOptions() {
|
||||||
let sites = document.getElementById("additional").value;
|
let sites = document.getElementById("additional").value;
|
||||||
let clickBehavior = document.querySelector('input[name="click-behavior"]:checked').value;
|
let clickBehavior = document.querySelector('input[name="click-behavior"]:checked').value;
|
||||||
let contextMenuClickBehavior = document.querySelector('input[name="context-menu-click-behavior"]:checked').value;
|
let contextMenuClickBehavior = document.querySelector('input[name="context-menu-click-behavior"]:checked').value;
|
||||||
|
let defaultFormat = document.getElementById('default_format').value
|
||||||
|
|
||||||
chrome.storage.sync.set({
|
chrome.storage.sync.set({
|
||||||
"metube": url,
|
"metube": url,
|
||||||
"sites": sites,
|
"sites": sites,
|
||||||
"clickBehavior": clickBehavior,
|
"clickBehavior": clickBehavior,
|
||||||
"contextMenuClickBehavior": contextMenuClickBehavior
|
"contextMenuClickBehavior": contextMenuClickBehavior,
|
||||||
|
"defaultFormat": defaultFormat,
|
||||||
}, function () {
|
}, function () {
|
||||||
document.getElementById("saved").classList.remove('hidden');
|
document.getElementById("saved").classList.remove('hidden');
|
||||||
|
|
||||||
|
|
@ -50,7 +52,8 @@ async function restoreOptions() {
|
||||||
'metube',
|
'metube',
|
||||||
'sites',
|
'sites',
|
||||||
'clickBehavior',
|
'clickBehavior',
|
||||||
'contextMenuClickBehavior'
|
'contextMenuClickBehavior',
|
||||||
|
'defaultFormat'
|
||||||
], function (data) {
|
], function (data) {
|
||||||
if (data.metube !== undefined) {
|
if (data.metube !== undefined) {
|
||||||
document.getElementById("metube").value = data.metube;
|
document.getElementById("metube").value = data.metube;
|
||||||
|
|
@ -67,6 +70,10 @@ async function restoreOptions() {
|
||||||
if (data.contextMenuClickBehavior !== undefined) {
|
if (data.contextMenuClickBehavior !== undefined) {
|
||||||
document.getElementById(data.contextMenuClickBehavior).checked = true;
|
document.getElementById(data.contextMenuClickBehavior).checked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.defaultFormat !== undefined) {
|
||||||
|
document.getElementById('default_format').value = data.defaultFormat;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue