Skip to content

Commit 41c8a07

Browse files
committed
fix formatting
1 parent b7319ee commit 41c8a07

File tree

2 files changed

+54
-88
lines changed

2 files changed

+54
-88
lines changed

background.js

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,29 @@ const menus = browser.menus || browser.contextMenus;
99

1010
function openInMpv(url) {
1111
const mpvUrl = `mpv://${url}`;
12-
13-
browser.tabs.update({ url: mpvUrl }).then(
14-
(tab) => {
15-
console.debug("navigating to:", mpvUrl);
16-
},
17-
(error) => {
18-
console.debug("failed " + mpvUrl, error);
19-
}
20-
);
12+
13+
browser.tabs.update({ url: mpvUrl }).then(() => {
14+
console.debug("navigating to:", mpvUrl);
15+
}, (error) => {
16+
console.debug("failed " + mpvUrl, error);
17+
});
2118
}
2219

2320
menus.create({
24-
id: "openInMpv",
25-
title: browser.i18n.getMessage("extensionName"),
26-
contexts: isChrome
27-
? [
28-
// chrome: action, all, audio, browser_action, editable, frame, image, launcher, link, page, page_action, selection, video
29-
"action",
30-
"audio",
31-
"browser_action",
32-
"frame",
33-
"image",
34-
"link",
35-
"page_action",
36-
"selection",
37-
"video",
38-
]
39-
: [
40-
// firefox: "all", "audio", "bookmark", "editable", "frame", "image", "launcher", "link", "page", "password", "selection", "tab", "tools_menu", "video"
41-
"action",
42-
"audio",
43-
"frame",
44-
"image",
45-
"link",
46-
"selection",
47-
"tab",
48-
"tools_menu",
49-
"video",
50-
],
21+
id: "openInMpv", //
22+
title: browser.i18n.getMessage("extensionName"), //
23+
// chrome: action, all, audio, browser_action, editable, frame, image, launcher, link, page, page_action, selection, video
24+
// firefox: "all", "audio", "bookmark", "editable", "frame", "image", "launcher", "link", "page", "password", "selection", "tab", "tools_menu", "video"
25+
contexts: isChrome ?
26+
["action", "audio", "browser_action", "frame", "image", "link", "page_action", "selection", "video",] :
27+
["action", "audio", "frame", "image", "link", "selection", "tab", "tools_menu", "video",],
5128
});
5229

5330
menus.onClicked.addListener((info, tab) => {
5431
switch (info.menuItemId) {
5532
case "openInMpv":
5633
const url = info.linkUrl || info.srcUrl || info.selectionText || info.frameUrl || info.pageUrl;
57-
if (url) openInMpv(url);
58-
else console.debug({ info: info, tab: tab });
34+
if (url) openInMpv(url); else console.debug({ info: info, tab: tab });
5935
break;
6036
}
6137
});
@@ -65,11 +41,9 @@ browser.action.onClicked.addListener((tab) => {
6541
});
6642

6743
const filter = {
68-
url: [
69-
{
70-
schemes: ["mpv", "mpvx"],
71-
},
72-
// {
44+
url: [{
45+
schemes: ["mpv", "mpvx"],
46+
}, // {
7347
// urlPrefix: browser.runtime.getURL("/"),
7448
// },
7549
],
@@ -79,13 +53,13 @@ if (!isChrome) {
7953
browser.webNavigation.onErrorOccurred.addListener((details) => {
8054
// Error code 2152398865 -> kNoContent (mpv)
8155
// Error code 2152398866 -> kUnknownProtocol
82-
56+
8357
if (details.error.endsWith("2152398865")) {
8458
console.debug("opened in mpv");
8559
} else {
8660
console.debug("onErrorOccurred");
8761
console.debug(details);
88-
62+
8963
browser.tabs.create({ url: "setup.sh" });
9064
}
9165
}, filter);

open-in-mpv.plugin.js

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,43 @@ const settings = { showAgain: true };
1010

1111
const contextMenuPatch = (tree, context) => {
1212
const href = context.target.href || context.target.parentNode.href
13-
13+
1414
if (href !== undefined) {
15-
tree.props.children.push(
16-
BdApi.ContextMenu.buildItem({
17-
type: "separator",
18-
})
19-
)
20-
tree.props.children.push(
21-
BdApi.ContextMenu.buildItem({
22-
type: "text",
23-
label: "open in mpv",
24-
action: () => {
25-
console.log("link is " + href);
26-
const electron = require('electron');
27-
28-
electron.shell.openExternal('mpv://' + href).then(() => {
29-
if (settings.showAgain !== false) {
30-
BdApi.UI.showConfirmationModal("Open in mpv", "Successfully opened " + href + " in mpv. Did nothing happen? Download and run setup.sh", {
31-
confirmText: "Download setup.sh",
32-
onConfirm: () => {
15+
tree.props.children.push(BdApi.ContextMenu.buildItem({
16+
type: "separator",
17+
}))
18+
tree.props.children.push(BdApi.ContextMenu.buildItem({
19+
type: "text", label: "open in mpv", action: () => {
20+
console.log("link is " + href);
21+
const electron = require('electron');
22+
23+
electron.shell.openExternal('mpv://' + href).then(() => {
24+
if (settings.showAgain !== false) {
25+
BdApi.UI.showConfirmationModal("Open in mpv",
26+
"Successfully opened " + href + " in mpv. Did nothing happen? Download and run setup.sh",
27+
{
28+
confirmText: "Download setup.sh", onConfirm: () => {
3329
electron.shell.openExternal('https://raw.githubusercontent.com/binarynoise/open-in-mpv/main/setup.sh');
3430
},
35-
36-
cancelText: "Ok, don't show again",
37-
onCancel: () => {
31+
32+
cancelText: "Ok, don't show again", onCancel: () => {
3833
settings.showAgain = false;
3934
BdApi.Data.save("open-in-mpv", "settings", settings);
4035
},
4136
})
42-
} else {
43-
BdApi.UI.showToast("" + href + " opened in mpv.", { type: "success" });
44-
}
45-
console.log("success");
46-
}, (error) => {
47-
console.log("failed to open mpv://" + href);
48-
console.log(error);
49-
}).catch((error) => {
50-
console.log("failed to open mpv://" + href);
51-
console.log(error);
52-
})
53-
},
54-
})
55-
)
37+
} else {
38+
BdApi.UI.showToast("" + href + " opened in mpv.", { type: "success" });
39+
}
40+
console.log("success");
41+
}, (error) => {
42+
console.log("failed to open mpv://" + href);
43+
console.log(error);
44+
}).catch((error) => {
45+
console.log("failed to open mpv://" + href);
46+
console.log(error);
47+
})
48+
},
49+
}))
5650
}
5751
};
5852

@@ -79,19 +73,17 @@ function buildSetting(text, key, type, value, callback = () => {
7973
module.exports = () => ({
8074
start() {
8175
console.log("Open in mpv plugin enabled");
82-
76+
8377
Object.assign(settings, BdApi.Data.load("open-in-mpv", "settings"));
8478
BdApi.ContextMenu.patch("message", contextMenuPatch);
85-
},
86-
stop() {
79+
}, stop() {
8780
BdApi.ContextMenu.unpatch("message", contextMenuPatch);
88-
},
89-
getSettingsPanel: () => {
81+
}, getSettingsPanel: () => {
9082
const mySettingsPanel = document.createElement("div", { className: "bd-addon-settings-wrap" });
9183
mySettingsPanel.id = "my-settings";
92-
84+
9385
const showAgain = buildSetting("Show Dialog", "showAgain", "checkbox", settings.showAgain);
94-
86+
9587
mySettingsPanel.append(showAgain);
9688
return mySettingsPanel;
9789
}

0 commit comments

Comments
 (0)