Compare commits

..

No commits in common. "55c3b548ca1e3bad497884da816940fd45410b44" and "46fd45bbaadac397dd85bab4f8b87c9a8e857f19" have entirely different histories.

6 changed files with 10 additions and 34 deletions

View File

@ -11,12 +11,6 @@ chrome.runtime.onInstalled.addListener(function () {
],
contexts: ['link'],
});
chrome.contextMenus.create({
id: 'metube-page',
title: "Send page to MeTube",
contexts: ['page'],
});
});
function sendVideoUrlToMetube(videoUrl, metubeUrl, format, advancedSettings, callback) {
@ -32,18 +26,15 @@ function sendVideoUrlToMetube(videoUrl, metubeUrl, format, advancedSettings, cal
let postData = {
"quality": "best",
"format": format,
"url": videoUrl,
'auto_start': !advancedSettings['disable_auto_start'] ?? true
"url": videoUrl
}
Object.keys(advancedSettings).forEach((key) => {
if (advancedSettings[key] && !['disable_auto_start'].includes(key) ) {
if (advancedSettings[key]) {
postData[key] = hostname.startsWith('www.') ? hostname.replace('www.', '') : hostname
}
})
console.log(postData)
fetch(metubeUrl + "/add", {
method: 'POST',
headers: {
@ -70,8 +61,7 @@ chrome.contextMenus.onClicked.addListener(function (item, tab) {
let needToSwitch = (data.contextMenuClickBehavior === 'context-menu-send-current-url-and-switch');
let videoUrl = item.linkUrl || item.pageUrl;
sendVideoUrlToMetube(videoUrl, data.metube, data.defaultFormat, data.advancedSettings, function () {
sendVideoUrlToMetube(item.linkUrl, data.metube, data.defaultFormat, data.advancedSettings, function () {
if (needToSwitch) {
openTab(data.metube, tab);
}
@ -100,7 +90,7 @@ chrome.action.onClicked.addListener(function (tab) {
// use this tab to get the youtube video URL
let videoUrl = tabs[0].url;
sendVideoUrlToMetube(videoUrl, data.metube, data.defaultFormat, data.advancedSettings, function () {
if (needToSwitch) {
if (!needToSwitch) {
openTab(data.metube, tab);
}
});

View File

@ -1,7 +1,7 @@
{
"name": "MeTube Downloader",
"description": "Use the context menu to send video into MeTube application",
"version": "1.7",
"version": "1.5",
"manifest_version": 3,
"permissions": ["contextMenus", "storage", "tabs"],
"background": {

View File

@ -58,7 +58,6 @@
<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>

View File

@ -12,15 +12,13 @@ async function saveOptions() {
let advancedElements = document.querySelectorAll('#advanced_settings input');
let advancedSettings = {
'folder': false,
'custom_name_prefix': false,
'disable_auto_start': false
};
let advancedSettings = {};
advancedElements.forEach((e) => {
advancedSettings[e.name] = e.checked ? true : false
})
console.log(advancedSettings)
chrome.storage.sync.set({
"metube": url,
"sites": sites,
@ -41,7 +39,7 @@ async function saveOptions() {
// todo: fix it
// also need make function for check string
// https://developer.chrome.com/docs/extensions/mv3/match_patterns/
if(!sites.length){
if(sites.length <= 1){
return;
}
@ -57,18 +55,6 @@ async function saveOptions() {
}
);
chrome.contextMenus.update(
'metube-page',
{
documentUrlPatterns: [
'https://www.youtube.com/*',
'https://m.youtube.com/*',
'https://youtu.be/*',
...sites
]
}
);
}
async function restoreOptions() {
@ -102,6 +88,7 @@ async function restoreOptions() {
if (data.advancedSettings !== undefined) {
Object.keys(data.advancedSettings).forEach((key) => {
console.log(key)
document.getElementById(key).checked = data.advancedSettings[key];
})
}