diff --git a/external-video.js b/external-video.js index 0bd545c..f08857f 100644 --- a/external-video.js +++ b/external-video.js @@ -1,11 +1,9 @@ var targetPages = [ - "*://*.youtube.com/watch*", + "*://*.youtube.com/watch?*", "*://*.twitch.tv/*", "*://*.vimeo.com/*", "*://*.streamable.com/*", "*://*.liveleak.com/view*", - "*://*.vid.me/*", - "*://*.funnyordie.com/videos/*", "*://*.dailymotion.com/video/*" ]; @@ -34,28 +32,47 @@ function restoreSettings() { } function openInMpv(request) { + if (!(request.type == "main_frame")) { + return { cancel: false }; + } + var lockedTabIndex = tabsLock.lastIndexOf(request.tabId); + if (!(lockedTabIndex == -1)) { + return { cancel: false }; + } + function closeTab(data) { + if (settings.mainClose) { + browser.tabs.remove(data.id); + } if (!data.active) { browser.tabs.remove(data.id); } } - if (request.type === "main_frame" && lockedTabIndex === -1) { - var command = `${request.url} --force-window=immediate ${settings.args}`; - + function mpvRun(data) { + var command = `${data.url} --force-window=immediate`; browser.runtime.sendNativeMessage("mpv", command); - var querying = browser.tabs.get(request.tabId); - querying.then(closeTab); - browser.history.addUrl({ - url: request.url + url: data.url }); - return { cancel: true }; + var querying = browser.tabs.get(data.tabId); + querying.then(closeTab); + } + + if (request.url == "https://www.twitch.tv/") { + return { cancel: false }; } + + if (request.url.includes("twitch.tv/directory")) { + return { cancel: false }; + } + + mpvRun(request); + return { cancel: true }; } chrome.contextMenus.create({ diff --git a/settings/options.html b/settings/options.html index 5d4312b..ec4e2ca 100644 --- a/settings/options.html +++ b/settings/options.html @@ -13,9 +13,16 @@ Options given to MPV +
+ +
+ diff --git a/settings/options.js b/settings/options.js index 4a60587..e179b74 100644 --- a/settings/options.js +++ b/settings/options.js @@ -1,16 +1,25 @@ function saveOptions(e) { - browser.storage.local.set({ - args: document.querySelector("#args").value - }); + browser.storage.local.set({ + args: document.querySelector("#args").value + }); + browser.storage.local.set({ + mainClose: document.querySelector("#mainClose").checked + }); + restoreOptions; } function restoreOptions() { - function setCurrentChoice(result) { - document.querySelector("#args").value = result.args || "--pause --ytdl-format='bestvideo[height<=?1080]+bestaudio/best'"; + function setArgs(result) { + document.querySelector("#args").value = result.args || "--pause --ytdl-format='bestvideo[height<=?1080]+bestaudio/best'"; } + function setMainClose(result) { + document.querySelector("#mainClose").checked = result.mainClose; + } - var getting = browser.storage.local.get("args"); - getting.then(setCurrentChoice); + var getting = browser.storage.local.get("args"); + getting.then(setArgs); + var getting = browser.storage.local.get("mainClose"); + getting.then(setMainClose); } document.addEventListener("DOMContentLoaded", restoreOptions);