diff --git a/.gitignore b/.gitignore index 720ba6c..46d8b81 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ +.vscode/ metube-browser-extension.pem \ No newline at end of file diff --git a/src/options.html b/src/options.html index b991c2a..22f7df5 100644 --- a/src/options.html +++ b/src/options.html @@ -12,23 +12,33 @@ margin: 5px; outline: none; } + textarea { + width: 100%; + height: 100px; + } .hidden { display: none; } + #saved { + color: green; + } -

About

This extension is context menu button for sending links of youtube videos into you own instance of MeTube

This extension won't work without installed MeTube. For additional instructions see github page of MeTube.

-

If you have some throubles with extension you can open issue on github page of extension.

-

 

-

Settings

+

If you have some troubles with extension you can open issue on github page of extension.

+

Settings

- +

Additional sites

+

Youtube-dl support many another sites 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

+

+ +

 

diff --git a/src/options.js b/src/options.js index d9bf068..96353c5 100644 --- a/src/options.js +++ b/src/options.js @@ -5,27 +5,57 @@ async function saveOptions() { url = url.slice(0, -1) } - chrome.storage.sync.set({"metube": url}, function () { + let sites = document.getElementById("additional").value; + + chrome.storage.sync.set({ "metube": url, "sites": sites }, function () { document.getElementById("saved").classList.remove('hidden'); setTimeout(function () { document.getElementById("saved").classList.add('hidden'); }, 1000 * 10) }); + + sites = splitLines(sites); + + // todo: fix it + // also need make function for check string + // https://developer.chrome.com/docs/extensions/mv3/match_patterns/ + if(sites.length <= 1){ + return; + } + + chrome.contextMenus.update( + 'metube', + { + targetUrlPatterns: [ + 'https://www.youtube.com/*', + 'https://m.youtube.com/*', + 'https://youtu.be/*', + ...sites + ] + } + ); + } async function restoreOptions() { - chrome.storage.sync.get(['metube'], function (data) { - if (data.metube === undefined) { - return + chrome.storage.sync.get(['metube', 'sites'], function (data) { + if (data.metube != undefined) { + document.getElementById("metube").value = data.metube; } - document.getElementById("metube").value = data.metube; + + if (data.sites != undefined) { + document.getElementById("additional").value = data.sites; + } + }); } -window.addEventListener("DOMContentLoaded", restoreOptions, {passive: true}); +function splitLines(t) { return t.split(/\r\n|\r|\n/); } + +window.addEventListener("DOMContentLoaded", restoreOptions, { passive: true }); document.querySelector("form").addEventListener("submit", (e) => { e.preventDefault(); saveOptions(); -}, {passive: false}); +}, { passive: false });