firefox-xdg-open: dont duplicate the menu entries
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
//! largely copied from OpenInMPV browser extension
|
//! see also: the OpenInMPV browser extension
|
||||||
|
//! dev docs:
|
||||||
|
//! - chrome.contextMenus API: <https://developer.chrome.com/docs/extensions/reference/api/contextMenus>
|
||||||
|
//! - OnClickData: <https://developer.chrome.com/docs/extensions/reference/api/contextMenus#type-OnClickData>
|
||||||
|
|
||||||
function xdgOpen(tabId, url) {
|
function xdgOpen(tabId, url) {
|
||||||
const code = `
|
const code = `
|
||||||
@@ -10,13 +13,11 @@ function xdgOpen(tabId, url) {
|
|||||||
chrome.tabs.executeScript(tabId, { code })
|
chrome.tabs.executeScript(tabId, { code })
|
||||||
}
|
}
|
||||||
|
|
||||||
[["page", "pageUrl"], ["link", "linkUrl"], ["video", "srcUrl"], ["audio", "srcUrl"]].forEach(([item, linkType]) => {
|
chrome.contextMenus.create({
|
||||||
chrome.contextMenus.create({
|
|
||||||
title: "xdg-open",
|
title: "xdg-open",
|
||||||
id: `open${item}inmpv`,
|
id: "xdg-open",
|
||||||
contexts: [item],
|
contexts: ["audio", "link", "page", "video"],
|
||||||
onclick: (info, tab) => {
|
onclick: (info /*: OnClickData*/, tab /*: Tab*/) => {
|
||||||
xdgOpen(tab.id, info[linkType]);
|
xdgOpen(tab.id, info.srcUrl || info.linkUrl || info.pageUrl);
|
||||||
},
|
},
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user