fix: firefox bugs

This commit is contained in:
Gabe
2025-10-11 11:19:33 +08:00
parent 9ace600fce
commit 96dfee90ab
10 changed files with 45 additions and 17 deletions

View File

@@ -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");

View File

@@ -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%,

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;
`,
// 模糊

View File

@@ -221,8 +221,7 @@ export default function Action({ translator, fab }) {
translator.toggle();
sendIframeMsg(MSG_TRANS_TOGGLE);
setShowPopup(false);
}
else {
} else {
setShowPopup((pre) => !pre);
}
}