firefox-xdg-open: dont duplicate the menu entries

This commit is contained in:
2024-12-20 01:18:58 +00:00
parent 6922387088
commit 14f6087143

View File

@@ -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: "xdg-open",
id: `open${item}inmpv`, contexts: ["audio", "link", "page", "video"],
contexts: [item], onclick: (info /*: OnClickData*/, tab /*: Tab*/) => {
onclick: (info, tab) => { xdgOpen(tab.id, info.srcUrl || info.linkUrl || info.pageUrl);
xdgOpen(tab.id, info[linkType]); },
},
});
}); });