-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexternal-video.js
71 lines (56 loc) · 1.52 KB
/
external-video.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var targetPages = [
"*://*.youtube.com/watch*",
"*://*.twitch.tv/*",
"*://*.vimeo.com/*",
"*://*.streamable.com/*",
"*://*.liveleak.com/view*",
"*://*.vid.me/*",
"*://*.funnyordie.com/videos/*",
"*://*.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
});
}
var creating = browser.tabs.create({});
creating.then(onCreated);
}
function restoreSettings() {
function setSettings(data) {
settings = data;
}
var getting = browser.storage.local.get();
getting.then(setSettings);
}
function openInMpv(request) {
var lockedTabIndex = tabsLock.lastIndexOf(request.tabId);
function closeTab(data) {
if (!data.active) {
browser.tabs.remove(data.id);
}
}
if (request.type === "main_frame" && lockedTabIndex === -1) {
var command = `${request.url} --force-window=immediate ${settings.args}`;
browser.runtime.sendNativeMessage("mpv", command);
var querying = browser.tabs.get(request.tabId);
querying.then(closeTab);
browser.history.addUrl({
url: request.url
});
return { cancel: true };
}
}
chrome.contextMenus.create({
id: "open_original",
title: "Open without MPV",
onclick: openOriginal,
contexts: ["link"]
});
browser.storage.onChanged.addListener(restoreSettings);
browser.webRequest.onBeforeRequest.addListener(openInMpv, { urls: targetPages }, ["blocking"]);
restoreSettings();