Mirror NoScript's badge copntent in the context menu to provide more info (e.g. on XSS or TG status) whenever the toolbar icon is hidden.
This commit is contained in:
parent
c6add32551
commit
a57c4cba84
|
@ -32,7 +32,18 @@
|
|||
let popupFor = tabId => `${popupURL}#tab${tabId}`;
|
||||
|
||||
let ctxMenuId = "noscript-ctx-menu";
|
||||
|
||||
let menuShowing = false;
|
||||
const menuUpdater = async (tabId) => {
|
||||
if (!menuShowing) return;
|
||||
try {
|
||||
let badgeText = await browser.browserAction.getBadgeText({tabId});
|
||||
let title = "NoScript";
|
||||
if (badgeText) title = `${title} [${badgeText}]`;
|
||||
await browser.contextMenus.update(ctxMenuId, {title});
|
||||
} catch (e) {
|
||||
// it might break in some load stages / with privileged page: don't spam the console
|
||||
}
|
||||
}
|
||||
async function toggleCtxMenuItem(show = ns.local.showCtxMenuItem) {
|
||||
if (!("contextMenus" in browser)) return;
|
||||
let id = ctxMenuId;
|
||||
|
@ -40,12 +51,16 @@
|
|||
await browser.contextMenus.remove(id);
|
||||
} catch (e) {}
|
||||
|
||||
if (show) {
|
||||
if (menuShowing = show) {
|
||||
browser.contextMenus.create({
|
||||
id,
|
||||
title: "NoScript",
|
||||
contexts: ["all"]
|
||||
});
|
||||
if (!browser.tabs.onUpdated.hasListener(menuUpdater)) {
|
||||
browser.tabs.onUpdated.addListener(menuUpdater);
|
||||
browser.tabs.onActivated.addListener(({tabId}) => menuUpdater(tabId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue