From b6bc165cf0aac2b19a66b610e6e1c834a4e6d841 Mon Sep 17 00:00:00 2001 From: Gabe Yuan Date: Mon, 11 Dec 2023 17:26:49 +0800 Subject: [PATCH] fix: context munus --- src/background.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/background.js b/src/background.js index 592e5eb..5182682 100644 --- a/src/background.js +++ b/src/background.js @@ -59,15 +59,7 @@ function addContextMenus() { * 清除右键菜单 */ function removeContextMenus() { - for (const id of [ - CMD_TOGGLE_TRANSLATE, - CMD_TOGGLE_STYLE, - CMD_OPEN_TRANBOX, - CMD_OPEN_OPTIONS, - "options_separator", - ]) { - browser.contextMenus.remove(id); - } + browser.contextMenus.removeAll(); } /** @@ -75,6 +67,9 @@ function removeContextMenus() { */ browser.runtime.onInstalled.addListener(() => { tryInitDefaultData(); + + // 右键菜单 + addContextMenus(); }); /** @@ -96,9 +91,7 @@ browser.runtime.onStartup.addListener(async () => { } // 右键菜单 - if (contextMenus) { - addContextMenus(); - } else { + if (!contextMenus) { removeContextMenus(); }