From 14f6087143b008c8045ef026cf0796b6707b66aa Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 20 Dec 2024 01:18:58 +0000 Subject: [PATCH] firefox-xdg-open: dont duplicate the menu entries --- .../firefox-xdg-open/background.js | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pkgs/by-name/firefox-extensions/firefox-xdg-open/background.js b/pkgs/by-name/firefox-extensions/firefox-xdg-open/background.js index 701b4aff5..038d7854d 100644 --- a/pkgs/by-name/firefox-extensions/firefox-xdg-open/background.js +++ b/pkgs/by-name/firefox-extensions/firefox-xdg-open/background.js @@ -1,4 +1,7 @@ -//! largely copied from OpenInMPV browser extension +//! see also: the OpenInMPV browser extension +//! dev docs: +//! - chrome.contextMenus API: +//! - OnClickData: function xdgOpen(tabId, url) { const code = ` @@ -10,13 +13,11 @@ function xdgOpen(tabId, url) { chrome.tabs.executeScript(tabId, { code }) } -[["page", "pageUrl"], ["link", "linkUrl"], ["video", "srcUrl"], ["audio", "srcUrl"]].forEach(([item, linkType]) => { - chrome.contextMenus.create({ - title: "xdg-open", - id: `open${item}inmpv`, - contexts: [item], - onclick: (info, tab) => { - xdgOpen(tab.id, info[linkType]); - }, - }); +chrome.contextMenus.create({ + title: "xdg-open", + id: "xdg-open", + contexts: ["audio", "link", "page", "video"], + onclick: (info /*: OnClickData*/, tab /*: Tab*/) => { + xdgOpen(tab.id, info.srcUrl || info.linkUrl || info.pageUrl); + }, });