Compare commits
16 Commits
46fd45bbaa
...
55c3b548ca
| Author | SHA1 | Date |
|---|---|---|
|
|
55c3b548ca | |
|
|
984c717e36 | |
|
|
cff03d5072 | |
|
|
af0f0a0985 | |
|
|
0eebd6fbea | |
|
|
dc51ce5734 | |
|
|
f166f505c9 | |
|
|
ff5fc0558d | |
|
|
beb78bfcce | |
|
|
a29f69520c | |
|
|
a545f0c6cb | |
|
|
e957c729f0 | |
|
|
84bafb56a0 | |
|
|
31d1d22563 | |
|
|
0b3dff4f89 | |
|
|
0fb491c02e |
Binary file not shown.
Binary file not shown.
|
|
@ -11,6 +11,12 @@ chrome.runtime.onInstalled.addListener(function () {
|
||||||
],
|
],
|
||||||
contexts: ['link'],
|
contexts: ['link'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
chrome.contextMenus.create({
|
||||||
|
id: 'metube-page',
|
||||||
|
title: "Send page to MeTube",
|
||||||
|
contexts: ['page'],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function sendVideoUrlToMetube(videoUrl, metubeUrl, format, advancedSettings, callback) {
|
function sendVideoUrlToMetube(videoUrl, metubeUrl, format, advancedSettings, callback) {
|
||||||
|
|
@ -26,15 +32,18 @@ function sendVideoUrlToMetube(videoUrl, metubeUrl, format, advancedSettings, cal
|
||||||
let postData = {
|
let postData = {
|
||||||
"quality": "best",
|
"quality": "best",
|
||||||
"format": format,
|
"format": format,
|
||||||
"url": videoUrl
|
"url": videoUrl,
|
||||||
|
'auto_start': !advancedSettings['disable_auto_start'] ?? true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Object.keys(advancedSettings).forEach((key) => {
|
Object.keys(advancedSettings).forEach((key) => {
|
||||||
if (advancedSettings[key]) {
|
if (advancedSettings[key] && !['disable_auto_start'].includes(key) ) {
|
||||||
postData[key] = hostname.startsWith('www.') ? hostname.replace('www.', '') : hostname
|
postData[key] = hostname.startsWith('www.') ? hostname.replace('www.', '') : hostname
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log(postData)
|
||||||
fetch(metubeUrl + "/add", {
|
fetch(metubeUrl + "/add", {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -61,7 +70,8 @@ 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, data.defaultFormat, data.advancedSettings, function () {
|
let videoUrl = item.linkUrl || item.pageUrl;
|
||||||
|
sendVideoUrlToMetube(videoUrl, data.metube, data.defaultFormat, data.advancedSettings, function () {
|
||||||
if (needToSwitch) {
|
if (needToSwitch) {
|
||||||
openTab(data.metube, tab);
|
openTab(data.metube, tab);
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +100,7 @@ chrome.action.onClicked.addListener(function (tab) {
|
||||||
// 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, data.defaultFormat, data.advancedSettings, function () {
|
sendVideoUrlToMetube(videoUrl, data.metube, data.defaultFormat, data.advancedSettings, 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.5",
|
"version": "1.7",
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"permissions": ["contextMenus", "storage", "tabs"],
|
"permissions": ["contextMenus", "storage", "tabs"],
|
||||||
"background": {
|
"background": {
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@
|
||||||
<div id="advanced_settings">
|
<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="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="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>
|
</div>
|
||||||
|
|
||||||
<h3>Additional sites</h3>
|
<h3>Additional sites</h3>
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,15 @@ async function saveOptions() {
|
||||||
|
|
||||||
let advancedElements = document.querySelectorAll('#advanced_settings input');
|
let advancedElements = document.querySelectorAll('#advanced_settings input');
|
||||||
|
|
||||||
let advancedSettings = {};
|
let advancedSettings = {
|
||||||
|
'folder': false,
|
||||||
|
'custom_name_prefix': false,
|
||||||
|
'disable_auto_start': false
|
||||||
|
};
|
||||||
advancedElements.forEach((e) => {
|
advancedElements.forEach((e) => {
|
||||||
advancedSettings[e.name] = e.checked ? true : false
|
advancedSettings[e.name] = e.checked ? true : false
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(advancedSettings)
|
|
||||||
|
|
||||||
chrome.storage.sync.set({
|
chrome.storage.sync.set({
|
||||||
"metube": url,
|
"metube": url,
|
||||||
"sites": sites,
|
"sites": sites,
|
||||||
|
|
@ -39,7 +41,7 @@ async function saveOptions() {
|
||||||
// todo: fix it
|
// todo: fix it
|
||||||
// also need make function for check string
|
// also need make function for check string
|
||||||
// https://developer.chrome.com/docs/extensions/mv3/match_patterns/
|
// https://developer.chrome.com/docs/extensions/mv3/match_patterns/
|
||||||
if(sites.length <= 1){
|
if(!sites.length){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,6 +57,18 @@ async function saveOptions() {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
chrome.contextMenus.update(
|
||||||
|
'metube-page',
|
||||||
|
{
|
||||||
|
documentUrlPatterns: [
|
||||||
|
'https://www.youtube.com/*',
|
||||||
|
'https://m.youtube.com/*',
|
||||||
|
'https://youtu.be/*',
|
||||||
|
...sites
|
||||||
|
]
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function restoreOptions() {
|
async function restoreOptions() {
|
||||||
|
|
@ -88,7 +102,6 @@ async function restoreOptions() {
|
||||||
|
|
||||||
if (data.advancedSettings !== undefined) {
|
if (data.advancedSettings !== undefined) {
|
||||||
Object.keys(data.advancedSettings).forEach((key) => {
|
Object.keys(data.advancedSettings).forEach((key) => {
|
||||||
console.log(key)
|
|
||||||
document.getElementById(key).checked = data.advancedSettings[key];
|
document.getElementById(key).checked = data.advancedSettings[key];
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue