forked from woodruffw/ff2mpv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ff2mpv.js
40 lines (34 loc) · 1.1 KB
/
ff2mpv.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
function onError(error) {
console.log(`${error}`);
}
function ff2mpv(url) {
browser.tabs.executeScript({
code: "video = document.getElementsByTagName('video');video[0].pause();"
});
browser.runtime.sendNativeMessage("ff2mpv", { url: url }).catch(onError);
}
async function getOS() {
return browser.runtime.getPlatformInfo().then((i) => i.os);
}
getOS().then((os) => {
var title = os == "win" ? "Play in MP&V" : "Play in MPV (&W)";
browser.contextMenus.create({
id: "ff2mpv",
title: title,
contexts: ["link", "image", "video", "audio", "selection", "frame"]
});
browser.contextMenus.onClicked.addListener((info, tab) => {
switch (info.menuItemId) {
case "ff2mpv":
/* These should be mutually exclusive, but,
if they aren't, this is a reasonable priority.
*/
url = info.linkUrl || info.srcUrl || info.selectionText || info.frameUrl;
if (url) ff2mpv(url);
break;
}
});
browser.browserAction.onClicked.addListener((tab) => {
ff2mpv(tab.url);
});
});