From daadc0195cef67f005edf731bede0b8aa09731c0 Mon Sep 17 00:00:00 2001 From: htyxyt <62530172+htyxyt@users.noreply.github.com> Date: Tue, 18 Feb 2025 10:25:12 +0800 Subject: [PATCH 01/12] Update background.thunderbird.js --- src/background.thunderbird.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/background.thunderbird.js b/src/background.thunderbird.js index 7b8e29c..ab0c5c0 100644 --- a/src/background.thunderbird.js +++ b/src/background.thunderbird.js @@ -1,3 +1,4 @@ +/* global messenger */ import browser from "webextension-polyfill"; import { MSG_FETCH, @@ -251,4 +252,4 @@ async function registerMsgDisplayScript() { js: [{file: "/content.js"}] }); } -registerMsgDisplayScript(); \ No newline at end of file +registerMsgDisplayScript(); From b0843f7d6689a10574766d4295d3bbf1460c7e59 Mon Sep 17 00:00:00 2001 From: htyxyt <62530172+htyxyt@users.noreply.github.com> Date: Tue, 18 Feb 2025 11:39:58 +0800 Subject: [PATCH 02/12] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 387eb47..3cd645b 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "build:chrome": "rm -rf build/chrome && BUILD_PATH=./build/chrome REACT_APP_CLIENT=chrome react-app-rewired build && rm build/chrome/content.html", "build:edge": "rm -rf build/edge && cp -r build/chrome build/edge", "build:firefox": "rm -rf build/firefox && cp -r build/chrome build/firefox && cat ./build/firefox/manifest.firefox.json > ./build/firefox/manifest.json && rm build/*/manifest.firefox.json", - "build:thunderbird":"rm -rf build/thunderbird && cp -r build/chrome build/thunderbird && cat ./build/thunderbird/manifest.thunderbird.json > ./build/thunderbird/manifest.json && cp ./build/thunderbird/backgroundthunderbird.js ./build/thunderbird/background.js && rm build/*/manifest.thunderbird.json && rm build/*/backgroundthunderbird.js && rm build/*/backgroundthunderbird.js.LICENSE.txt", + "build:thunderbird": "rm -rf build/thunderbird && BUILD_PATH=./build/thunderbird REACT_APP_CLIENT=thunderbird react-app-rewired build && cp ./build/thunderbird/manifest.thunderbird.json ./build/thunderbird/manifest.json && rm build/thunderbird/manifest.thunderbird.json", "build:web": "rm -rf build/web && BUILD_PATH=./build/web REACT_APP_CLIENT=userscript react-app-rewired build", "build:userscript-ios": "file1=build/web/kiss-translator.user.js file2=build/web/kiss-translator-ios-safari.user.js && cp $file1 $file2 && sed -i 's|// @grant unsafeWindow|// @inject-into content|g' $file2", "build:userscript": "rm -rf build/userscript && mkdir build/userscript && cp build/web/*.user.js build/userscript/", From dd46a8450c2098b048e63826df3ffb2772ea0e3e Mon Sep 17 00:00:00 2001 From: htyxyt <62530172+htyxyt@users.noreply.github.com> Date: Tue, 18 Feb 2025 11:41:28 +0800 Subject: [PATCH 03/12] Update config-overrides.js --- config-overrides.js | 1 - 1 file changed, 1 deletion(-) diff --git a/config-overrides.js b/config-overrides.js index 1058630..4826e3b 100644 --- a/config-overrides.js +++ b/config-overrides.js @@ -31,7 +31,6 @@ const extWebpack = (config, env) => { popup: paths.appSrc + "/popup.js", options: paths.appSrc + "/options.js", background: paths.appSrc + "/background.js", - backgroundthunderbird: paths.appSrc + "/background.thunderbird.js", content: paths.appSrc + "/content.js", }; From f31675d8a2200612b99961e3aca149aa5868d46c Mon Sep 17 00:00:00 2001 From: htyxyt <62530172+htyxyt@users.noreply.github.com> Date: Tue, 18 Feb 2025 11:42:05 +0800 Subject: [PATCH 04/12] Update index.js --- src/config/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/config/index.js b/src/config/index.js index cea947f..e4c1256 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -39,7 +39,8 @@ export const CLIENT_CHROME = "chrome"; export const CLIENT_EDGE = "edge"; export const CLIENT_FIREFOX = "firefox"; export const CLIENT_USERSCRIPT = "userscript"; -export const CLIENT_EXTS = [CLIENT_CHROME, CLIENT_EDGE, CLIENT_FIREFOX]; +export const CLIENT_THUNDERBIRD = "thunderbird"; +export const CLIENT_EXTS = [CLIENT_CHROME, CLIENT_EDGE, CLIENT_FIREFOX, CLIENT_THUNDERBIRD]; export const KV_RULES_KEY = "kiss-rules.json"; export const KV_WORDS_KEY = "kiss-words.json"; From 52b7f6a225f290bff70ee26fbb02eb640dd89e65 Mon Sep 17 00:00:00 2001 From: htyxyt <62530172+htyxyt@users.noreply.github.com> Date: Tue, 18 Feb 2025 11:42:47 +0800 Subject: [PATCH 05/12] Update background.js --- src/background.js | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/background.js b/src/background.js index 0e62e7f..2f8759e 100644 --- a/src/background.js +++ b/src/background.js @@ -41,44 +41,44 @@ const REMOVE_HEADERS = [ /** * 添加右键菜单 */ -async function addContextMenus(contextMenuType = 1) { +async function addmenus(contextMenuType = 1) { // 添加前先删除,避免重复ID的错误 try { - await browser.contextMenus.removeAll(); + await browser.menus.removeAll(); } catch (err) { // } switch (contextMenuType) { case 1: - browser.contextMenus.create({ + browser.menus.create({ id: CMD_TOGGLE_TRANSLATE, title: browser.i18n.getMessage("app_name"), contexts: ["page", "selection"], }); break; case 2: - browser.contextMenus.create({ + browser.menus.create({ id: CMD_TOGGLE_TRANSLATE, title: browser.i18n.getMessage("toggle_translate"), contexts: ["page", "selection"], }); - browser.contextMenus.create({ + browser.menus.create({ id: CMD_TOGGLE_STYLE, title: browser.i18n.getMessage("toggle_style"), contexts: ["page", "selection"], }); - browser.contextMenus.create({ + browser.menus.create({ id: CMD_OPEN_TRANBOX, title: browser.i18n.getMessage("open_tranbox"), contexts: ["page", "selection"], }); - browser.contextMenus.create({ + browser.menus.create({ id: "options_separator", type: "separator", contexts: ["page", "selection"], }); - browser.contextMenus.create({ + browser.menus.create({ id: CMD_OPEN_OPTIONS, title: browser.i18n.getMessage("open_options"), contexts: ["page", "selection"], @@ -123,14 +123,28 @@ async function updateCspRules(csplist = DEFAULT_CSPLIST.join(",\n")) { } } +/** + * 注册邮件显示脚本 + */ +async function registerMsgDisplayScript() { + await messenger.messageDisplayScripts.register({ + js: [{file: "/content.js"}] + }); + } + /** * 插件安装 */ browser.runtime.onInstalled.addListener(() => { tryInitDefaultData(); + //在thunderbird中注册脚本 + if (process.env.REACT_APP_CLIENT === "thunderbird") { + registerMsgDisplayScript(); + } + // 右键菜单 - addContextMenus(); + addmenus(); // 禁用CSP updateCspRules(); @@ -139,7 +153,7 @@ browser.runtime.onInstalled.addListener(() => { /** * 浏览器启动 */ -browser.runtime.onStartup.addListener(async () => { +browser.runtime.onStartup.addListener(async () => { // 同步数据 await trySyncSettingAndRules(); @@ -151,9 +165,14 @@ browser.runtime.onStartup.addListener(async () => { tryClearCaches(); } + //在thunderbird中注册脚本 + if (process.env.REACT_APP_CLIENT === "thunderbird") { + registerMsgDisplayScript(); + } + // 右键菜单 // firefox重启后菜单会消失,故重复添加 - addContextMenus(contextMenuType); + addmenus(contextMenuType); // 禁用CSP updateCspRules(csplist); @@ -193,7 +212,7 @@ browser.runtime.onMessage.addListener(async ({ action, args }) => { case MSG_UPDATE_CSP: return await updateCspRules(args); case MSG_CONTEXT_MENUS: - return await addContextMenus(args); + return await addmenus(args); case MSG_COMMAND_SHORTCUTS: return await browser.commands.getAll(); default: @@ -226,7 +245,7 @@ browser.commands.onCommand.addListener((command) => { /** * 监听右键菜单 */ -browser.contextMenus.onClicked.addListener(({ menuItemId }) => { +browser.menus.onClicked.addListener(({ menuItemId }) => { switch (menuItemId) { case CMD_TOGGLE_TRANSLATE: sendTabMsg(MSG_TRANS_TOGGLE); From 4b5ed30e5baad3c14d9aaaded2c80191a6360301 Mon Sep 17 00:00:00 2001 From: htyxyt <62530172+htyxyt@users.noreply.github.com> Date: Tue, 18 Feb 2025 11:42:57 +0800 Subject: [PATCH 06/12] Delete src/background.thunderbird.js --- src/background.thunderbird.js | 255 ---------------------------------- 1 file changed, 255 deletions(-) delete mode 100644 src/background.thunderbird.js diff --git a/src/background.thunderbird.js b/src/background.thunderbird.js deleted file mode 100644 index ab0c5c0..0000000 --- a/src/background.thunderbird.js +++ /dev/null @@ -1,255 +0,0 @@ -/* global messenger */ -import browser from "webextension-polyfill"; -import { - MSG_FETCH, - MSG_GET_HTTPCACHE, - MSG_TRANS_TOGGLE, - MSG_OPEN_OPTIONS, - MSG_SAVE_RULE, - MSG_TRANS_TOGGLE_STYLE, - MSG_OPEN_TRANBOX, - MSG_CONTEXT_MENUS, - MSG_COMMAND_SHORTCUTS, - MSG_INJECT_JS, - MSG_INJECT_CSS, - MSG_UPDATE_CSP, - DEFAULT_CSPLIST, - CMD_TOGGLE_TRANSLATE, - CMD_TOGGLE_STYLE, - CMD_OPEN_OPTIONS, - CMD_OPEN_TRANBOX, -} from "./config"; -import { getSettingWithDefault, tryInitDefaultData } from "./libs/storage"; -import { trySyncSettingAndRules } from "./libs/sync"; -import { fetchHandle, getHttpCache } from "./libs/fetch"; -import { sendTabMsg } from "./libs/msg"; -import { trySyncAllSubRules } from "./libs/subRules"; -import { tryClearCaches } from "./libs"; -import { saveRule } from "./libs/rules"; -import { getCurTabId } from "./libs/msg"; -import { injectInlineJs, injectInternalCss } from "./libs/injector"; -import { kissLog } from "./libs/log"; - -globalThis.ContextType = "BACKGROUND"; - -const REMOVE_HEADERS = [ - `content-security-policy`, - `content-security-policy-report-only`, - `x-webkit-csp`, - `x-content-security-policy`, -]; - -/** - * 添加右键菜单 - */ -async function addmenus(contextMenuType = 1) { - // 添加前先删除,避免重复ID的错误 - try { - await browser.menus.removeAll(); - } catch (err) { - // - } - - switch (contextMenuType) { - case 1: - browser.menus.create({ - id: CMD_TOGGLE_TRANSLATE, - title: browser.i18n.getMessage("app_name"), - contexts: ["page", "selection"], - }); - break; - case 2: - browser.menus.create({ - id: CMD_TOGGLE_TRANSLATE, - title: browser.i18n.getMessage("toggle_translate"), - contexts: ["page", "selection"], - }); - browser.menus.create({ - id: CMD_TOGGLE_STYLE, - title: browser.i18n.getMessage("toggle_style"), - contexts: ["page", "selection"], - }); - browser.menus.create({ - id: CMD_OPEN_TRANBOX, - title: browser.i18n.getMessage("open_tranbox"), - contexts: ["page", "selection"], - }); - browser.menus.create({ - id: "options_separator", - type: "separator", - contexts: ["page", "selection"], - }); - browser.menus.create({ - id: CMD_OPEN_OPTIONS, - title: browser.i18n.getMessage("open_options"), - contexts: ["page", "selection"], - }); - break; - default: - } -} - -/** - * 更新CSP策略 - * @param {*} csplist - */ -async function updateCspRules(csplist = DEFAULT_CSPLIST.join(",\n")) { - try { - const newRules = csplist - .split(/\n|,/) - .map((url) => url.trim()) - .filter(Boolean) - .map((url, idx) => ({ - id: idx + 1, - action: { - type: "modifyHeaders", - responseHeaders: REMOVE_HEADERS.map((header) => ({ - operation: "remove", - header, - })), - }, - condition: { - urlFilter: url, - resourceTypes: ["main_frame", "sub_frame"], - }, - })); - const oldRules = await browser.declarativeNetRequest.getDynamicRules(); - const oldRuleIds = oldRules.map((rule) => rule.id); - await browser.declarativeNetRequest.updateDynamicRules({ - removeRuleIds: oldRuleIds, - addRules: newRules, - }); - } catch (err) { - kissLog(err, "update csp rules"); - } -} - -/** - * 插件安装 - */ -browser.runtime.onInstalled.addListener(() => { - tryInitDefaultData(); - - // 右键菜单 - addmenus(); - - // 禁用CSP - updateCspRules(); -}); - -/** - * 浏览器启动 - */ -browser.runtime.onStartup.addListener(async () => { - // 同步数据 - await trySyncSettingAndRules(); - - const { clearCache, contextMenuType, subrulesList, csplist } = - await getSettingWithDefault(); - - // 清除缓存 - if (clearCache) { - tryClearCaches(); - } - - // 右键菜单 - // firefox重启后菜单会消失,故重复添加 - addmenus(contextMenuType); - - // 禁用CSP - updateCspRules(csplist); - - // 同步订阅规则 - trySyncAllSubRules({ subrulesList }); -}); - -/** - * 监听消息 - */ -browser.runtime.onMessage.addListener(async ({ action, args }) => { - switch (action) { - case MSG_FETCH: - return await fetchHandle(args); - case MSG_GET_HTTPCACHE: - const { input, init } = args; - return await getHttpCache(input, init); - case MSG_OPEN_OPTIONS: - return await browser.runtime.openOptionsPage(); - case MSG_SAVE_RULE: - return await saveRule(args); - case MSG_INJECT_JS: - return await browser.scripting.executeScript({ - target: { tabId: await getCurTabId(), allFrames: true }, - func: injectInlineJs, - args: [args], - world: "MAIN", - }); - case MSG_INJECT_CSS: - return await browser.scripting.executeScript({ - target: { tabId: await getCurTabId(), allFrames: true }, - func: injectInternalCss, - args: [args], - world: "MAIN", - }); - case MSG_UPDATE_CSP: - return await updateCspRules(args); - case MSG_CONTEXT_MENUS: - return await addmenus(args); - case MSG_COMMAND_SHORTCUTS: - return await browser.commands.getAll(); - default: - throw new Error(`message action is unavailable: ${action}`); - } -}); - -/** - * 监听快捷键 - */ -browser.commands.onCommand.addListener((command) => { - // console.log(`Command: ${command}`); - switch (command) { - case CMD_TOGGLE_TRANSLATE: - sendTabMsg(MSG_TRANS_TOGGLE); - break; - case CMD_OPEN_TRANBOX: - sendTabMsg(MSG_OPEN_TRANBOX); - break; - case CMD_TOGGLE_STYLE: - sendTabMsg(MSG_TRANS_TOGGLE_STYLE); - break; - case CMD_OPEN_OPTIONS: - browser.runtime.openOptionsPage(); - break; - default: - } -}); - -/** - * 监听右键菜单 - */ -browser.menus.onClicked.addListener(({ menuItemId }) => { - switch (menuItemId) { - case CMD_TOGGLE_TRANSLATE: - sendTabMsg(MSG_TRANS_TOGGLE); - break; - case CMD_TOGGLE_STYLE: - sendTabMsg(MSG_TRANS_TOGGLE_STYLE); - break; - case CMD_OPEN_TRANBOX: - sendTabMsg(MSG_OPEN_TRANBOX); - break; - case CMD_OPEN_OPTIONS: - browser.runtime.openOptionsPage(); - break; - default: - } -}); -/** - * 邮件显示中注册脚本 - */ -async function registerMsgDisplayScript() { - await messenger.messageDisplayScripts.register({ - js: [{file: "/content.js"}] - }); - } -registerMsgDisplayScript(); From 537378a038da600e802099339aaa2562119a48d8 Mon Sep 17 00:00:00 2001 From: htyxyt <62530172+htyxyt@users.noreply.github.com> Date: Tue, 18 Feb 2025 11:45:57 +0800 Subject: [PATCH 07/12] Update background.js --- src/background.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/background.js b/src/background.js index 2f8759e..0672a43 100644 --- a/src/background.js +++ b/src/background.js @@ -1,3 +1,4 @@ +/* global messenger */ import browser from "webextension-polyfill"; import { MSG_FETCH, From 467745c1e936b867d93066b33668d62995bd487b Mon Sep 17 00:00:00 2001 From: htyxyt <62530172+htyxyt@users.noreply.github.com> Date: Tue, 18 Feb 2025 11:58:39 +0800 Subject: [PATCH 08/12] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3cd645b..b6d3e29 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ "start:userscript": "REACT_APP_CLIENT=userscript react-app-rewired start", "build:chrome": "rm -rf build/chrome && BUILD_PATH=./build/chrome REACT_APP_CLIENT=chrome react-app-rewired build && rm build/chrome/content.html", "build:edge": "rm -rf build/edge && cp -r build/chrome build/edge", + "build:thunderbird": "rm -rf build/thunderbird && BUILD_PATH=./build/thunderbird REACT_APP_CLIENT=thunderbird react-app-rewired build && cp ./build/thunderbird/manifest.thunderbird.json ./build/thunderbird/manifest.json && rm build/*/manifest.thunderbird.json", "build:firefox": "rm -rf build/firefox && cp -r build/chrome build/firefox && cat ./build/firefox/manifest.firefox.json > ./build/firefox/manifest.json && rm build/*/manifest.firefox.json", - "build:thunderbird": "rm -rf build/thunderbird && BUILD_PATH=./build/thunderbird REACT_APP_CLIENT=thunderbird react-app-rewired build && cp ./build/thunderbird/manifest.thunderbird.json ./build/thunderbird/manifest.json && rm build/thunderbird/manifest.thunderbird.json", "build:web": "rm -rf build/web && BUILD_PATH=./build/web REACT_APP_CLIENT=userscript react-app-rewired build", "build:userscript-ios": "file1=build/web/kiss-translator.user.js file2=build/web/kiss-translator-ios-safari.user.js && cp $file1 $file2 && sed -i 's|// @grant unsafeWindow|// @inject-into content|g' $file2", "build:userscript": "rm -rf build/userscript && mkdir build/userscript && cp build/web/*.user.js build/userscript/", From d27ebd90b6d5b4c2cce63f37f196d40d882760c2 Mon Sep 17 00:00:00 2001 From: htyxyt <62530172+htyxyt@users.noreply.github.com> Date: Tue, 18 Feb 2025 12:14:02 +0800 Subject: [PATCH 09/12] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b6d3e29..004f005 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "build:userscript-ios": "file1=build/web/kiss-translator.user.js file2=build/web/kiss-translator-ios-safari.user.js && cp $file1 $file2 && sed -i 's|// @grant unsafeWindow|// @inject-into content|g' $file2", "build:userscript": "rm -rf build/userscript && mkdir build/userscript && cp build/web/*.user.js build/userscript/", "build:rules": "babel-node src/rules.js", - "build": "pnpm build:chrome && pnpm build:edge && pnpm build:firefox && pnpm build:thunderbird && pnpm build:web && pnpm build:userscript-ios && pnpm build:userscript && pnpm build:rules", + "build": "pnpm build:chrome && pnpm build:edge && pnpm build:thunderbird && pnpm build:firefox && pnpm build:web && pnpm build:userscript-ios && pnpm build:userscript && pnpm build:rules", "zip": "cd build && zip -r chrome.zip chrome && zip -r edge.zip edge && (cd firefox && zip -r ../firefox.zip .) && (cd thunderbird && zip -r ../thunderbird.zip .)", "test": "react-app-rewired test", "eject": "react-scripts eject" From c1c59caa10a2dcb4c22350c82f2c03c55ec119f0 Mon Sep 17 00:00:00 2001 From: htyxyt <62530172+htyxyt@users.noreply.github.com> Date: Tue, 18 Feb 2025 12:29:43 +0800 Subject: [PATCH 10/12] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 004f005..bd33ce9 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "start:userscript": "REACT_APP_CLIENT=userscript react-app-rewired start", "build:chrome": "rm -rf build/chrome && BUILD_PATH=./build/chrome REACT_APP_CLIENT=chrome react-app-rewired build && rm build/chrome/content.html", "build:edge": "rm -rf build/edge && cp -r build/chrome build/edge", - "build:thunderbird": "rm -rf build/thunderbird && BUILD_PATH=./build/thunderbird REACT_APP_CLIENT=thunderbird react-app-rewired build && cp ./build/thunderbird/manifest.thunderbird.json ./build/thunderbird/manifest.json && rm build/*/manifest.thunderbird.json", + "build:thunderbird": "rm -rf build/thunderbird && BUILD_PATH=./build/thunderbird REACT_APP_CLIENT=thunderbird react-app-rewired build && rm build/chrome/content.html && cp ./build/thunderbird/manifest.thunderbird.json ./build/thunderbird/manifest.json && rm build/*/manifest.thunderbird.json", "build:firefox": "rm -rf build/firefox && cp -r build/chrome build/firefox && cat ./build/firefox/manifest.firefox.json > ./build/firefox/manifest.json && rm build/*/manifest.firefox.json", "build:web": "rm -rf build/web && BUILD_PATH=./build/web REACT_APP_CLIENT=userscript react-app-rewired build", "build:userscript-ios": "file1=build/web/kiss-translator.user.js file2=build/web/kiss-translator-ios-safari.user.js && cp $file1 $file2 && sed -i 's|// @grant unsafeWindow|// @inject-into content|g' $file2", From 8a2144f2633904c5adf3ccc5c6af0fdd8619ef55 Mon Sep 17 00:00:00 2001 From: htyxyt <62530172+htyxyt@users.noreply.github.com> Date: Tue, 18 Feb 2025 12:44:06 +0800 Subject: [PATCH 11/12] Update background.js --- src/background.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/background.js b/src/background.js index 0672a43..779faad 100644 --- a/src/background.js +++ b/src/background.js @@ -42,7 +42,7 @@ const REMOVE_HEADERS = [ /** * 添加右键菜单 */ -async function addmenus(contextMenuType = 1) { +async function addContextMenus(contextMenuType = 1) { // 添加前先删除,避免重复ID的错误 try { await browser.menus.removeAll(); @@ -145,7 +145,7 @@ browser.runtime.onInstalled.addListener(() => { } // 右键菜单 - addmenus(); + addContextMenus(); // 禁用CSP updateCspRules(); @@ -154,7 +154,7 @@ browser.runtime.onInstalled.addListener(() => { /** * 浏览器启动 */ -browser.runtime.onStartup.addListener(async () => { +browser.runtime.onStartup.addListener(async () => { // 同步数据 await trySyncSettingAndRules(); @@ -173,7 +173,7 @@ browser.runtime.onStartup.addListener(async () => { // 右键菜单 // firefox重启后菜单会消失,故重复添加 - addmenus(contextMenuType); + addContextMenus(contextMenuType); // 禁用CSP updateCspRules(csplist); @@ -213,7 +213,7 @@ browser.runtime.onMessage.addListener(async ({ action, args }) => { case MSG_UPDATE_CSP: return await updateCspRules(args); case MSG_CONTEXT_MENUS: - return await addmenus(args); + return await addContextMenus(args); case MSG_COMMAND_SHORTCUTS: return await browser.commands.getAll(); default: @@ -246,7 +246,7 @@ browser.commands.onCommand.addListener((command) => { /** * 监听右键菜单 */ -browser.menus.onClicked.addListener(({ menuItemId }) => { +browser.contextMenus.onClicked.addListener(({ menuItemId }) => { switch (menuItemId) { case CMD_TOGGLE_TRANSLATE: sendTabMsg(MSG_TRANS_TOGGLE); From 3dc8f393f2659b824df163726226701b73a41ece Mon Sep 17 00:00:00 2001 From: htyxyt <62530172+htyxyt@users.noreply.github.com> Date: Tue, 18 Feb 2025 12:56:29 +0800 Subject: [PATCH 12/12] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bd33ce9..664602a 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "start:userscript": "REACT_APP_CLIENT=userscript react-app-rewired start", "build:chrome": "rm -rf build/chrome && BUILD_PATH=./build/chrome REACT_APP_CLIENT=chrome react-app-rewired build && rm build/chrome/content.html", "build:edge": "rm -rf build/edge && cp -r build/chrome build/edge", - "build:thunderbird": "rm -rf build/thunderbird && BUILD_PATH=./build/thunderbird REACT_APP_CLIENT=thunderbird react-app-rewired build && rm build/chrome/content.html && cp ./build/thunderbird/manifest.thunderbird.json ./build/thunderbird/manifest.json && rm build/*/manifest.thunderbird.json", + "build:thunderbird": "rm -rf build/thunderbird && BUILD_PATH=./build/thunderbird REACT_APP_CLIENT=thunderbird react-app-rewired build && rm build/thunderbird/content.html && cp ./build/thunderbird/manifest.thunderbird.json ./build/thunderbird/manifest.json && rm build/*/manifest.thunderbird.json", "build:firefox": "rm -rf build/firefox && cp -r build/chrome build/firefox && cat ./build/firefox/manifest.firefox.json > ./build/firefox/manifest.json && rm build/*/manifest.firefox.json", "build:web": "rm -rf build/web && BUILD_PATH=./build/web REACT_APP_CLIENT=userscript react-app-rewired build", "build:userscript-ios": "file1=build/web/kiss-translator.user.js file2=build/web/kiss-translator-ios-safari.user.js && cp $file1 $file2 && sed -i 's|// @grant unsafeWindow|// @inject-into content|g' $file2",