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
+
+
+
+