fix: firefox bugs
This commit is contained in:
@@ -94,8 +94,10 @@ const userscriptWebpack = (config, env) => {
|
|||||||
// @grant unsafeWindow
|
// @grant unsafeWindow
|
||||||
// @connect translate.googleapis.com
|
// @connect translate.googleapis.com
|
||||||
// @connect translate-pa.googleapis.com
|
// @connect translate-pa.googleapis.com
|
||||||
|
// @connect generativelanguage.googleapis.com
|
||||||
// @connect api-edge.cognitive.microsofttranslator.com
|
// @connect api-edge.cognitive.microsofttranslator.com
|
||||||
// @connect edge.microsoft.com
|
// @connect edge.microsoft.com
|
||||||
|
// @connect cn.bing.com
|
||||||
// @connect api-free.deepl.com
|
// @connect api-free.deepl.com
|
||||||
// @connect api.deepl.com
|
// @connect api.deepl.com
|
||||||
// @connect www2.deepl.com
|
// @connect www2.deepl.com
|
||||||
@@ -112,6 +114,10 @@ const userscriptWebpack = (config, env) => {
|
|||||||
// @connect transmart.qq.com
|
// @connect transmart.qq.com
|
||||||
// @connect niutrans.com
|
// @connect niutrans.com
|
||||||
// @connect translate.volcengine.com
|
// @connect translate.volcengine.com
|
||||||
|
// @connect dict.youdao.com
|
||||||
|
// @connect api.anthropic.com
|
||||||
|
// @connect api.cloudflare.com
|
||||||
|
// @connect openrouter.ai
|
||||||
// @connect localhost
|
// @connect localhost
|
||||||
// @connect 127.0.0.1
|
// @connect 127.0.0.1
|
||||||
// @run-at document-end
|
// @run-at document-end
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
"build:safari": "node src/scripts/build-safari.js",
|
"build:safari": "node src/scripts/build-safari.js",
|
||||||
"build:edge": "rm -rf build/edge && cp -r build/chrome build/edge",
|
"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: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: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-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:userscript": "rm -rf build/userscript && mkdir build/userscript && cp build/web/*.user.js build/userscript/",
|
||||||
|
|||||||
@@ -17,10 +17,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"web_accessible_resources": [
|
"web_accessible_resources": [
|
||||||
{
|
"injector.js"
|
||||||
"resources": ["injector.js"],
|
|
||||||
"matches": ["https://www.youtube.com/*"]
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
"commands": {
|
"commands": {
|
||||||
"_execute_browser_action": {
|
"_execute_browser_action": {
|
||||||
|
|||||||
@@ -23,10 +23,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"web_accessible_resources": [
|
"web_accessible_resources": [
|
||||||
{
|
"injector.js"
|
||||||
"resources": ["injector.js"],
|
|
||||||
"matches": ["https://www.youtube.com/*"]
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
"commands": {
|
"commands": {
|
||||||
"_execute_browser_action": {
|
"_execute_browser_action": {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import { isBuiltinAIAvailable } from "../libs/browser";
|
|||||||
import { chromeDetect, chromeTranslate } from "../libs/builtinAI";
|
import { chromeDetect, chromeTranslate } from "../libs/builtinAI";
|
||||||
import { fnPolyfill } from "../libs/fetch";
|
import { fnPolyfill } from "../libs/fetch";
|
||||||
import { getFetchPool } from "../libs/pool";
|
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 host = "https://cn.bing.com";
|
||||||
const url = `${host}/dict/search?q=${text}`;
|
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 parser = new DOMParser();
|
||||||
const doc = parser.parseFromString(str, "text/html");
|
const doc = parser.parseFromString(str, "text/html");
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export const OPT_TIMING_ALL = [
|
|||||||
OPT_TIMING_ALT,
|
OPT_TIMING_ALT,
|
||||||
];
|
];
|
||||||
|
|
||||||
const DEFAULT_DIY_STYLE = `color: #333;
|
export const DEFAULT_DIY_STYLE = `color: #333;
|
||||||
background: linear-gradient(
|
background: linear-gradient(
|
||||||
45deg,
|
45deg,
|
||||||
LightGreen 20%,
|
LightGreen 20%,
|
||||||
|
|||||||
@@ -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 client = process.env.REACT_APP_CLIENT;
|
||||||
export const isExt = CLIENT_EXTS.includes(client);
|
export const isExt = CLIENT_EXTS.includes(client);
|
||||||
export const isGm = client === CLIENT_USERSCRIPT;
|
export const isGm = client === CLIENT_USERSCRIPT;
|
||||||
export const isWeb = client === CLIENT_WEB;
|
export const isWeb = client === CLIENT_WEB;
|
||||||
|
export const isFirefox = client === CLIENT_FIREFOX;
|
||||||
|
|||||||
@@ -15,12 +15,20 @@ export const shortcutListener = (
|
|||||||
const pressedKeys = new Set();
|
const pressedKeys = new Set();
|
||||||
|
|
||||||
const handleKeyDown = (e) => {
|
const handleKeyDown = (e) => {
|
||||||
|
if (!e.code) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (pressedKeys.has(e.code)) return;
|
if (pressedKeys.has(e.code)) return;
|
||||||
pressedKeys.add(e.code);
|
pressedKeys.add(e.code);
|
||||||
onKeyDown(new Set(pressedKeys), e);
|
onKeyDown(new Set(pressedKeys), e);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleKeyUp = (e) => {
|
const handleKeyUp = (e) => {
|
||||||
|
if (!e.code) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// onKeyUp 应该在 key 从集合中移除前触发,以便判断组合键
|
// onKeyUp 应该在 key 从集合中移除前触发,以便判断组合键
|
||||||
onKeyUp(new Set(pressedKeys), e);
|
onKeyUp(new Set(pressedKeys), e);
|
||||||
pressedKeys.delete(e.code);
|
pressedKeys.delete(e.code);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
OPT_STYLE_HIGHLIGHT,
|
OPT_STYLE_HIGHLIGHT,
|
||||||
OPT_STYLE_BLOCKQUOTE,
|
OPT_STYLE_BLOCKQUOTE,
|
||||||
OPT_STYLE_DIY,
|
OPT_STYLE_DIY,
|
||||||
|
DEFAULT_DIY_STYLE,
|
||||||
DEFAULT_COLOR,
|
DEFAULT_COLOR,
|
||||||
} from "../config";
|
} 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]: ``,
|
[OPT_STYLE_NONE]: ``,
|
||||||
// 下划线
|
// 下划线
|
||||||
@@ -46,9 +50,8 @@ const genStyles = ({ textDiyStyle, bgColor = DEFAULT_COLOR }) => ({
|
|||||||
// 虚线框
|
// 虚线框
|
||||||
[OPT_STYLE_DASHBOX]: `
|
[OPT_STYLE_DASHBOX]: `
|
||||||
border: 1px dashed ${bgColor || DEFAULT_COLOR};
|
border: 1px dashed ${bgColor || DEFAULT_COLOR};
|
||||||
background: transparent;
|
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 0.2em 0.5em;
|
padding: 0.2em 0.4em;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
`,
|
`,
|
||||||
// 模糊
|
// 模糊
|
||||||
|
|||||||
@@ -221,8 +221,7 @@ export default function Action({ translator, fab }) {
|
|||||||
translator.toggle();
|
translator.toggle();
|
||||||
sendIframeMsg(MSG_TRANS_TOGGLE);
|
sendIframeMsg(MSG_TRANS_TOGGLE);
|
||||||
setShowPopup(false);
|
setShowPopup(false);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
setShowPopup((pre) => !pre);
|
setShowPopup((pre) => !pre);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user