From 6e9cd8a94ea163be30856192b0abcbecae8806f0 Mon Sep 17 00:00:00 2001 From: quinn <6AA4FD@airmail.cc> Date: Thu, 20 Dec 2018 15:32:49 -0800 Subject: [PATCH 1/5] fixes and twitch logic - disabled funnyordie because it's not working - took video namespace off funnyordie because it doesn't reflect site structure - added logic to determine if a twitch candidate is a stream or not --- external-video.js | 76 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 24 deletions(-) diff --git a/external-video.js b/external-video.js index 0bd545c..6e32f7f 100644 --- a/external-video.js +++ b/external-video.js @@ -1,20 +1,20 @@ var targetPages = [ - "*://*.youtube.com/watch*", - "*://*.twitch.tv/*", - "*://*.vimeo.com/*", - "*://*.streamable.com/*", - "*://*.liveleak.com/view*", - "*://*.vid.me/*", - "*://*.funnyordie.com/videos/*", - "*://*.dailymotion.com/video/*" + "*://*.youtube.com/watch?*", + "*://*.twitch.tv/*", + "*://*.vimeo.com/*", + "*://*.streamable.com/*", + "*://*.liveleak.com/view*", + // "*://*.vid.me/*", // vidme is suspended + // "*://*.funnyordie.com/*", // youtube-dl returns unsupported for these + "*://*.dailymotion.com/video/*" ]; var settings = {}; var tabsLock = []; function openOriginal(info, tab) { - function onCreated(tab) { - tabsLock.push(tab.id); + function onCreated(tab) { + tabsLock.push(tab.id); browser.tabs.update(tab.id, { url: info.linkUrl }); @@ -34,28 +34,52 @@ function restoreSettings() { } function openInMpv(request) { - var lockedTabIndex = tabsLock.lastIndexOf(request.tabId); + if (!(request.type == "main_frame")) { + console.log("ignoring a background request"); + return { cancel: false }; + } + + var lockedTabIndex = tabsLock.lastIndexOf(request.tabId); - function closeTab(data) { - if (!data.active) { - browser.tabs.remove(data.id); + if (!(lockedTabIndex == -1)) { + console.log("tab has been set to ignore") + return { cancel: false }; } - } - if (request.type === "main_frame" && lockedTabIndex === -1) { - var command = `${request.url} --force-window=immediate ${settings.args}`; + console.log("new candidate:", request.url, "type is:", request.type); - browser.runtime.sendNativeMessage("mpv", command); + function closeTab(data) { + if (!data.active) { + browser.tabs.remove(data.id); + } + } - var querying = browser.tabs.get(request.tabId); - querying.then(closeTab); + function mpvRun(data) { + var command = `${data.url} --force-window=immediate`; + console.log("running mpv", command); + browser.runtime.sendNativeMessage("mpv", command); - browser.history.addUrl({ - url: request.url - }); + browser.history.addUrl({ + url: data.url + }); + + var querying = browser.tabs.get(data.tabId); + querying.then(closeTab); + } + if (request.url == "https://www.twitch.tv/") { + console.log("this url is not a twitch stream"); + return { cancel: false }; + } + + if (request.url.includes("twitch.tv/directory")) { + console.log("this candidate is not a twitch stream"); + return { cancel: false }; + } + + console.log("running the supported url"); + mpvRun(request); return { cancel: true }; - } } chrome.contextMenus.create({ @@ -65,6 +89,10 @@ chrome.contextMenus.create({ contexts: ["link"] }); +function logRequest(request){ + console.log("opening ", request.url) +} + browser.storage.onChanged.addListener(restoreSettings); browser.webRequest.onBeforeRequest.addListener(openInMpv, { urls: targetPages }, ["blocking"]); From 90b0cdbd29c2a05ea566830c8fb6b19e2165be03 Mon Sep 17 00:00:00 2001 From: quinn <6AA4FD@airmail.cc> Date: Thu, 20 Dec 2018 16:06:44 -0800 Subject: [PATCH 2/5] take out logRequest --- external-video.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/external-video.js b/external-video.js index 6e32f7f..6daa138 100644 --- a/external-video.js +++ b/external-video.js @@ -89,10 +89,6 @@ chrome.contextMenus.create({ contexts: ["link"] }); -function logRequest(request){ - console.log("opening ", request.url) -} - browser.storage.onChanged.addListener(restoreSettings); browser.webRequest.onBeforeRequest.addListener(openInMpv, { urls: targetPages }, ["blocking"]); From 58665c1e30957d2696bb76fb385ee880521cad10 Mon Sep 17 00:00:00 2001 From: quinn <6AA4FD@airmail.cc> Date: Thu, 20 Dec 2018 17:11:07 -0800 Subject: [PATCH 3/5] Add mainclose setting Added setting to choose whether it's okay to close the main tab if it gets opened in mpv --- external-video.js | 24 ++++++++++++++---------- settings/options.html | 7 +++++++ settings/options.js | 24 +++++++++++++++++------- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/external-video.js b/external-video.js index 6daa138..b3b19ce 100644 --- a/external-video.js +++ b/external-video.js @@ -15,13 +15,13 @@ var tabsLock = []; function openOriginal(info, tab) { function onCreated(tab) { tabsLock.push(tab.id); - browser.tabs.update(tab.id, { - url: info.linkUrl - }); - } + browser.tabs.update(tab.id, { + url: info.linkUrl + }); + } - var creating = browser.tabs.create({}); - creating.then(onCreated); + var creating = browser.tabs.create({}); + creating.then(onCreated); } function restoreSettings() { @@ -29,15 +29,16 @@ function restoreSettings() { settings = data; } - var getting = browser.storage.local.get(); - getting.then(setSettings); + var getting = browser.storage.local.get(); + getting.then(setSettings); } function openInMpv(request) { + console.log("mainClose:", settings.mainClose); if (!(request.type == "main_frame")) { console.log("ignoring a background request"); - return { cancel: false }; - } + return { cancel: false }; + } var lockedTabIndex = tabsLock.lastIndexOf(request.tabId); @@ -49,6 +50,9 @@ function openInMpv(request) { console.log("new candidate:", request.url, "type is:", request.type); function closeTab(data) { + if (settings.mainClose) { + browser.tabs.remove(data.id); + } if (!data.active) { browser.tabs.remove(data.id); } 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..952290b 100644 --- a/settings/options.js +++ b/settings/options.js @@ -1,16 +1,26 @@ 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) { + // console.log("mainclose is", result.mainClose); + 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); From 271d3de6de9a3f036f15aaf7ffb15baf614e0c87 Mon Sep 17 00:00:00 2001 From: quinn <6AA4FD@airmail.cc> Date: Fri, 21 Dec 2018 12:35:21 -0800 Subject: [PATCH 4/5] Remove old lines and debug messages --- external-video.js | 15 ++------------- settings/options.js | 1 - 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/external-video.js b/external-video.js index b3b19ce..766acc8 100644 --- a/external-video.js +++ b/external-video.js @@ -4,8 +4,6 @@ var targetPages = [ "*://*.vimeo.com/*", "*://*.streamable.com/*", "*://*.liveleak.com/view*", - // "*://*.vid.me/*", // vidme is suspended - // "*://*.funnyordie.com/*", // youtube-dl returns unsupported for these "*://*.dailymotion.com/video/*" ]; @@ -34,21 +32,16 @@ function restoreSettings() { } function openInMpv(request) { - console.log("mainClose:", settings.mainClose); if (!(request.type == "main_frame")) { - console.log("ignoring a background request"); - return { cancel: false }; - } + return { cancel: false }; + } var lockedTabIndex = tabsLock.lastIndexOf(request.tabId); if (!(lockedTabIndex == -1)) { - console.log("tab has been set to ignore") return { cancel: false }; } - console.log("new candidate:", request.url, "type is:", request.type); - function closeTab(data) { if (settings.mainClose) { browser.tabs.remove(data.id); @@ -60,7 +53,6 @@ function openInMpv(request) { function mpvRun(data) { var command = `${data.url} --force-window=immediate`; - console.log("running mpv", command); browser.runtime.sendNativeMessage("mpv", command); browser.history.addUrl({ @@ -72,16 +64,13 @@ function openInMpv(request) { } if (request.url == "https://www.twitch.tv/") { - console.log("this url is not a twitch stream"); return { cancel: false }; } if (request.url.includes("twitch.tv/directory")) { - console.log("this candidate is not a twitch stream"); return { cancel: false }; } - console.log("running the supported url"); mpvRun(request); return { cancel: true }; } diff --git a/settings/options.js b/settings/options.js index 952290b..e179b74 100644 --- a/settings/options.js +++ b/settings/options.js @@ -13,7 +13,6 @@ function restoreOptions() { document.querySelector("#args").value = result.args || "--pause --ytdl-format='bestvideo[height<=?1080]+bestaudio/best'"; } function setMainClose(result) { - // console.log("mainclose is", result.mainClose); document.querySelector("#mainClose").checked = result.mainClose; } From 367614e4b6af5ce465cf3e10c7f7a92118536bd0 Mon Sep 17 00:00:00 2001 From: quinn <6AA4FD@airmail.cc> Date: Fri, 21 Dec 2018 12:44:58 -0800 Subject: [PATCH 5/5] Fix indent level --- external-video.js | 94 +++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/external-video.js b/external-video.js index 766acc8..f08857f 100644 --- a/external-video.js +++ b/external-video.js @@ -1,25 +1,25 @@ var targetPages = [ - "*://*.youtube.com/watch?*", - "*://*.twitch.tv/*", - "*://*.vimeo.com/*", - "*://*.streamable.com/*", - "*://*.liveleak.com/view*", - "*://*.dailymotion.com/video/*" + "*://*.youtube.com/watch?*", + "*://*.twitch.tv/*", + "*://*.vimeo.com/*", + "*://*.streamable.com/*", + "*://*.liveleak.com/view*", + "*://*.dailymotion.com/video/*" ]; var settings = {}; var tabsLock = []; function openOriginal(info, tab) { - function onCreated(tab) { - tabsLock.push(tab.id); - browser.tabs.update(tab.id, { - url: info.linkUrl - }); - } + function onCreated(tab) { + tabsLock.push(tab.id); + browser.tabs.update(tab.id, { + url: info.linkUrl + }); + } - var creating = browser.tabs.create({}); - creating.then(onCreated); + var creating = browser.tabs.create({}); + creating.then(onCreated); } function restoreSettings() { @@ -27,52 +27,52 @@ function restoreSettings() { settings = data; } - var getting = browser.storage.local.get(); - getting.then(setSettings); + var getting = browser.storage.local.get(); + getting.then(setSettings); } function openInMpv(request) { - if (!(request.type == "main_frame")) { - return { cancel: false }; - } + if (!(request.type == "main_frame")) { + return { cancel: false }; + } - var lockedTabIndex = tabsLock.lastIndexOf(request.tabId); + var lockedTabIndex = tabsLock.lastIndexOf(request.tabId); - if (!(lockedTabIndex == -1)) { - return { cancel: false }; - } + 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); - } + function closeTab(data) { + if (settings.mainClose) { + browser.tabs.remove(data.id); + } + if (!data.active) { + browser.tabs.remove(data.id); } + } - function mpvRun(data) { - var command = `${data.url} --force-window=immediate`; - browser.runtime.sendNativeMessage("mpv", command); + function mpvRun(data) { + var command = `${data.url} --force-window=immediate`; + browser.runtime.sendNativeMessage("mpv", command); - browser.history.addUrl({ - url: data.url - }); + browser.history.addUrl({ + url: data.url + }); - var querying = browser.tabs.get(data.tabId); - querying.then(closeTab); - } + var querying = browser.tabs.get(data.tabId); + querying.then(closeTab); + } - if (request.url == "https://www.twitch.tv/") { - return { cancel: false }; - } + if (request.url == "https://www.twitch.tv/") { + return { cancel: false }; + } - if (request.url.includes("twitch.tv/directory")) { - return { cancel: false }; - } + if (request.url.includes("twitch.tv/directory")) { + return { cancel: false }; + } - mpvRun(request); - return { cancel: true }; + mpvRun(request); + return { cancel: true }; } chrome.contextMenus.create({