Merge pull request #16 from mutschler/patch-3
Add advanced Options (subfolder, prefix, autostart)
This commit is contained in:
commit
af0f0a0985
|
|
@ -13,7 +13,7 @@ chrome.runtime.onInstalled.addListener(function () {
|
|||
});
|
||||
});
|
||||
|
||||
function sendVideoUrlToMetube(videoUrl, metubeUrl, format, callback) {
|
||||
function sendVideoUrlToMetube(videoUrl, metubeUrl, format, advancedSettings, callback) {
|
||||
console.log("Sending videoUrl=" + videoUrl + " to metubeUrl=" + metubeUrl);
|
||||
|
||||
if (typeof callback !== 'function') {
|
||||
|
|
@ -21,17 +21,30 @@ function sendVideoUrlToMetube(videoUrl, metubeUrl, format, callback) {
|
|||
};
|
||||
}
|
||||
|
||||
let {hostname} = new URL(videoUrl)
|
||||
|
||||
let postData = {
|
||||
"quality": "best",
|
||||
"format": format,
|
||||
"url": videoUrl,
|
||||
'auto_start': !advancedSettings['disable_auto_start'] ?? true
|
||||
}
|
||||
|
||||
|
||||
Object.keys(advancedSettings).forEach((key) => {
|
||||
if (advancedSettings[key] && !['disable_auto_start'].includes(key) ) {
|
||||
postData[key] = hostname.startsWith('www.') ? hostname.replace('www.', '') : hostname
|
||||
}
|
||||
})
|
||||
|
||||
console.log(postData)
|
||||
fetch(metubeUrl + "/add", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
"quality": "best",
|
||||
"format": format,
|
||||
"url": videoUrl
|
||||
})
|
||||
body: JSON.stringify(postData)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(function (response) {
|
||||
|
|
@ -43,7 +56,7 @@ function sendVideoUrlToMetube(videoUrl, metubeUrl, format, callback) {
|
|||
}
|
||||
|
||||
chrome.contextMenus.onClicked.addListener(function (item, tab) {
|
||||
chrome.storage.sync.get(['metube', 'contextMenuClickBehavior', 'defaultFormat'], function (data) {
|
||||
chrome.storage.sync.get(['metube', 'contextMenuClickBehavior', 'defaultFormat', 'advancedSettings'], function (data) {
|
||||
if (data === undefined || !data.hasOwnProperty('metube') || data.metube === "") {
|
||||
openTab(chrome.runtime.getURL('options.html'), tab);
|
||||
return
|
||||
|
|
@ -51,7 +64,7 @@ chrome.contextMenus.onClicked.addListener(function (item, tab) {
|
|||
|
||||
let needToSwitch = (data.contextMenuClickBehavior === 'context-menu-send-current-url-and-switch');
|
||||
|
||||
sendVideoUrlToMetube(item.linkUrl, data.metube, data.defaultFormat, function () {
|
||||
sendVideoUrlToMetube(item.linkUrl, data.metube, data.defaultFormat, data.advancedSettings, function () {
|
||||
if (needToSwitch) {
|
||||
openTab(data.metube, tab);
|
||||
}
|
||||
|
|
@ -60,7 +73,7 @@ chrome.contextMenus.onClicked.addListener(function (item, tab) {
|
|||
});
|
||||
|
||||
chrome.action.onClicked.addListener(function (tab) {
|
||||
chrome.storage.sync.get(['metube', 'clickBehavior', 'defaultFormat'], function (data) {
|
||||
chrome.storage.sync.get(['metube', 'clickBehavior', 'defaultFormat', 'advancedSettings'], function (data) {
|
||||
if (data === undefined || !data.hasOwnProperty('metube') || data.metube === "") {
|
||||
openTab(chrome.runtime.getURL('options.html'), tab);
|
||||
return
|
||||
|
|
@ -79,7 +92,7 @@ chrome.action.onClicked.addListener(function (tab) {
|
|||
}, function (tabs) {
|
||||
// use this tab to get the youtube video URL
|
||||
let videoUrl = tabs[0].url;
|
||||
sendVideoUrlToMetube(videoUrl, data.metube, data.defaultFormat, function () {
|
||||
sendVideoUrlToMetube(videoUrl, data.metube, data.defaultFormat, data.advancedSettings, function () {
|
||||
if (needToSwitch) {
|
||||
openTab(data.metube, tab);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,13 @@
|
|||
<input type="radio" name="context-menu-click-behavior" id="context-menu-send-current-url" value="context-menu-send-current-url"><label for="context-menu-send-current-url">Send the video URL to MeTube (no tab switch)</label><br>
|
||||
<input type="radio" name="context-menu-click-behavior" id="context-menu-send-current-url-and-switch" value="context-menu-send-current-url-and-switch"><label for="context-menu-send-current-url-and-switch">Send the video URL to MeTube and switch to MeTube</label><br>
|
||||
|
||||
<h4>Advanced Settings:</h4>
|
||||
<div id="advanced_settings">
|
||||
<input type="checkbox" name="folder" id="folder" value="true"><label for="folder">Use subfolder based on the Hostname of the URL</label><br>
|
||||
<input type="checkbox" name="custom_name_prefix" id="custom_name_prefix" value="true"><label for="custom_name_prefix">Use name-prefix based on the Hostname of the URL</label><br>
|
||||
<input type="checkbox" name="disable_auto_start" id="disable_auto_start" value="true"><label for="disable_auto_start">Disable auto start of Downloads</label><br>
|
||||
</div>
|
||||
|
||||
<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><textarea name="additional" id="additional" placeholder="https://vimeo.com/*
|
||||
|
|
|
|||
|
|
@ -10,12 +10,24 @@ async function saveOptions() {
|
|||
let contextMenuClickBehavior = document.querySelector('input[name="context-menu-click-behavior"]:checked').value;
|
||||
let defaultFormat = document.getElementById('default_format').value
|
||||
|
||||
let advancedElements = document.querySelectorAll('#advanced_settings input');
|
||||
|
||||
let advancedSettings = {
|
||||
'folder': false,
|
||||
'custom_name_prefix': false,
|
||||
'disable_auto_start': false
|
||||
};
|
||||
advancedElements.forEach((e) => {
|
||||
advancedSettings[e.name] = e.checked ? true : false
|
||||
})
|
||||
|
||||
chrome.storage.sync.set({
|
||||
"metube": url,
|
||||
"sites": sites,
|
||||
"clickBehavior": clickBehavior,
|
||||
"contextMenuClickBehavior": contextMenuClickBehavior,
|
||||
"defaultFormat": defaultFormat,
|
||||
"advancedSettings": advancedSettings
|
||||
}, function () {
|
||||
document.getElementById("saved").classList.remove('hidden');
|
||||
|
||||
|
|
@ -53,7 +65,8 @@ async function restoreOptions() {
|
|||
'sites',
|
||||
'clickBehavior',
|
||||
'contextMenuClickBehavior',
|
||||
'defaultFormat'
|
||||
'defaultFormat',
|
||||
'advancedSettings'
|
||||
], function (data) {
|
||||
if (data.metube !== undefined) {
|
||||
document.getElementById("metube").value = data.metube;
|
||||
|
|
@ -74,6 +87,12 @@ async function restoreOptions() {
|
|||
if (data.defaultFormat !== undefined) {
|
||||
document.getElementById('default_format').value = data.defaultFormat;
|
||||
}
|
||||
|
||||
if (data.advancedSettings !== undefined) {
|
||||
Object.keys(data.advancedSettings).forEach((key) => {
|
||||
document.getElementById(key).checked = data.advancedSettings[key];
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue