diff --git a/config-overrides.js b/config-overrides.js index d279188..b927059 100644 --- a/config-overrides.js +++ b/config-overrides.js @@ -94,8 +94,10 @@ const userscriptWebpack = (config, env) => { // @grant unsafeWindow // @connect translate.googleapis.com // @connect translate-pa.googleapis.com +// @connect generativelanguage.googleapis.com // @connect api-edge.cognitive.microsofttranslator.com // @connect edge.microsoft.com +// @connect cn.bing.com // @connect api-free.deepl.com // @connect api.deepl.com // @connect www2.deepl.com @@ -112,6 +114,10 @@ const userscriptWebpack = (config, env) => { // @connect transmart.qq.com // @connect niutrans.com // @connect translate.volcengine.com +// @connect dict.youdao.com +// @connect api.anthropic.com +// @connect api.cloudflare.com +// @connect openrouter.ai // @connect localhost // @connect 127.0.0.1 // @run-at document-end diff --git a/package.json b/package.json index 7421297..bd8763e 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "build:safari": "node src/scripts/build-safari.js", "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/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:firefox": "rm -rf build/firefox && BUILD_PATH=./build/firefox REACT_APP_CLIENT=firefox react-app-rewired build && rm build/firefox/content.html && 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", "build:userscript": "rm -rf build/userscript && mkdir build/userscript && cp build/web/*.user.js build/userscript/", diff --git a/public/manifest.firefox.json b/public/manifest.firefox.json index d676206..c95855d 100644 --- a/public/manifest.firefox.json +++ b/public/manifest.firefox.json @@ -17,10 +17,7 @@ } ], "web_accessible_resources": [ - { - "resources": ["injector.js"], - "matches": ["https://www.youtube.com/*"] - } + "injector.js" ], "commands": { "_execute_browser_action": { diff --git a/public/manifest.thunderbird.json b/public/manifest.thunderbird.json index 2944fad..f3f6e14 100644 --- a/public/manifest.thunderbird.json +++ b/public/manifest.thunderbird.json @@ -23,10 +23,7 @@ } ], "web_accessible_resources": [ - { - "resources": ["injector.js"], - "matches": ["https://www.youtube.com/*"] - } + "injector.js" ], "commands": { "_execute_browser_action": { diff --git a/src/apis/index.js b/src/apis/index.js index bad3a4d..494daf8 100644 --- a/src/apis/index.js +++ b/src/apis/index.js @@ -28,6 +28,7 @@ import { isBuiltinAIAvailable } from "../libs/browser"; import { chromeDetect, chromeTranslate } from "../libs/builtinAI"; import { fnPolyfill } from "../libs/fetch"; import { getFetchPool } from "../libs/pool"; +import { isFirefox } from "../libs/client"; /** * 同步数据 @@ -135,7 +136,18 @@ export const apiMicrosoftDict = async (text) => { const host = "https://cn.bing.com"; const url = `${host}/dict/search?q=${text}`; - const str = await fetchData(url, {}, { useCache: false }); + let str = ""; + if (isFirefox) { + const response = await fetch(url); + if (response.ok) { + str = await response.text(); + } + } else { + str = await fetchData(url, {}, { useCache: false }); + } + if (!str) { + return null; + } const parser = new DOMParser(); const doc = parser.parseFromString(str, "text/html"); diff --git a/src/config/rules.js b/src/config/rules.js index 83c1a3e..ce9c82e 100644 --- a/src/config/rules.js +++ b/src/config/rules.js @@ -57,7 +57,7 @@ export const OPT_TIMING_ALL = [ OPT_TIMING_ALT, ]; -const DEFAULT_DIY_STYLE = `color: #333; +export const DEFAULT_DIY_STYLE = `color: #333; background: linear-gradient( 45deg, LightGreen 20%, diff --git a/src/libs/client.js b/src/libs/client.js index 4dfdd77..96b3b60 100644 --- a/src/libs/client.js +++ b/src/libs/client.js @@ -1,6 +1,12 @@ -import { CLIENT_EXTS, CLIENT_USERSCRIPT, CLIENT_WEB } from "../config"; +import { + CLIENT_EXTS, + CLIENT_USERSCRIPT, + CLIENT_WEB, + CLIENT_FIREFOX, +} from "../config"; export const client = process.env.REACT_APP_CLIENT; export const isExt = CLIENT_EXTS.includes(client); export const isGm = client === CLIENT_USERSCRIPT; export const isWeb = client === CLIENT_WEB; +export const isFirefox = client === CLIENT_FIREFOX; diff --git a/src/libs/shortcut.js b/src/libs/shortcut.js index b396d0f..43d7ac5 100644 --- a/src/libs/shortcut.js +++ b/src/libs/shortcut.js @@ -15,12 +15,20 @@ export const shortcutListener = ( const pressedKeys = new Set(); const handleKeyDown = (e) => { + if (!e.code) { + return; + } + if (pressedKeys.has(e.code)) return; pressedKeys.add(e.code); onKeyDown(new Set(pressedKeys), e); }; const handleKeyUp = (e) => { + if (!e.code) { + return; + } + // onKeyUp 应该在 key 从集合中移除前触发,以便判断组合键 onKeyUp(new Set(pressedKeys), e); pressedKeys.delete(e.code); diff --git a/src/libs/style.js b/src/libs/style.js index e87206d..9770572 100644 --- a/src/libs/style.js +++ b/src/libs/style.js @@ -10,6 +10,7 @@ import { OPT_STYLE_HIGHLIGHT, OPT_STYLE_BLOCKQUOTE, OPT_STYLE_DIY, + DEFAULT_DIY_STYLE, DEFAULT_COLOR, } from "../config"; @@ -32,7 +33,10 @@ const genLineStyle = (style, color) => ` } `; -const genStyles = ({ textDiyStyle, bgColor = DEFAULT_COLOR }) => ({ +export const genStyles = ({ + textDiyStyle = DEFAULT_DIY_STYLE, + bgColor = DEFAULT_COLOR, +}) => ({ // 无样式 [OPT_STYLE_NONE]: ``, // 下划线 @@ -46,9 +50,8 @@ const genStyles = ({ textDiyStyle, bgColor = DEFAULT_COLOR }) => ({ // 虚线框 [OPT_STYLE_DASHBOX]: ` border: 1px dashed ${bgColor || DEFAULT_COLOR}; - background: transparent; display: inline-block; - padding: 0.2em 0.5em; + padding: 0.2em 0.4em; box-sizing: border-box; `, // 模糊 diff --git a/src/views/Action/index.js b/src/views/Action/index.js index 00fe1d2..61c30f6 100644 --- a/src/views/Action/index.js +++ b/src/views/Action/index.js @@ -221,8 +221,7 @@ export default function Action({ translator, fab }) { translator.toggle(); sendIframeMsg(MSG_TRANS_TOGGLE); setShowPopup(false); - } - else { + } else { setShowPopup((pre) => !pre); } }