feat: supported translation all when page opened
This commit is contained in:
@@ -183,13 +183,17 @@ export const I18N = {
|
||||
zh: `翻译服务`,
|
||||
en: `Translate Service`,
|
||||
},
|
||||
mouseover_translation: {
|
||||
zh: `鼠标悬停翻译`,
|
||||
en: `Mouseover translation`,
|
||||
translate_timing: {
|
||||
zh: `翻译时机`,
|
||||
en: `Translate Timing`,
|
||||
},
|
||||
mk_disable: {
|
||||
zh: `禁用`,
|
||||
en: `Disable`,
|
||||
zh: `滚动加载(建议)`,
|
||||
en: `Rolling Loading (Suggested)`,
|
||||
},
|
||||
mk_pageopen: {
|
||||
zh: `页面打开`,
|
||||
en: `Page Open`,
|
||||
},
|
||||
mk_mouseover: {
|
||||
zh: `鼠标悬停`,
|
||||
|
||||
@@ -298,12 +298,14 @@ export const OPT_STYLE_USE_COLOR = [
|
||||
];
|
||||
|
||||
export const OPT_MOUSEKEY_DISABLE = "mk_disable";
|
||||
export const OPT_MOUSEKEY_PAGEOPEN = "mk_pageopen";
|
||||
export const OPT_MOUSEKEY_MOUSEOVER = "mk_mouseover";
|
||||
export const OPT_MOUSEKEY_CONTROL = "mk_ctrlKey";
|
||||
export const OPT_MOUSEKEY_SHIFT = "mk_shiftKey";
|
||||
export const OPT_MOUSEKEY_ALT = "mk_altKey";
|
||||
export const OPT_MOUSEKEY_ALL = [
|
||||
OPT_MOUSEKEY_DISABLE,
|
||||
OPT_MOUSEKEY_PAGEOPEN,
|
||||
OPT_MOUSEKEY_MOUSEOVER,
|
||||
OPT_MOUSEKEY_CONTROL,
|
||||
OPT_MOUSEKEY_SHIFT,
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
OPT_STYLE_FUZZY,
|
||||
SHADOW_KEY,
|
||||
OPT_MOUSEKEY_DISABLE,
|
||||
OPT_MOUSEKEY_PAGEOPEN,
|
||||
OPT_MOUSEKEY_MOUSEOVER,
|
||||
DEFAULT_TRANS_APIS,
|
||||
} from "../config";
|
||||
@@ -293,6 +294,11 @@ export class Translator {
|
||||
this._tranNodes.forEach((_, node) => {
|
||||
this._interseObserver.observe(node);
|
||||
});
|
||||
} else if (this._setting.mouseKey === OPT_MOUSEKEY_PAGEOPEN) {
|
||||
// 全文直接翻译
|
||||
this._tranNodes.forEach((_, node) => {
|
||||
this._render(node);
|
||||
});
|
||||
} else {
|
||||
// 监听鼠标悬停
|
||||
window.addEventListener("keydown", this._handleKeydown);
|
||||
@@ -376,6 +382,10 @@ export class Translator {
|
||||
// 移除已插入元素
|
||||
node.querySelector(APP_LCNAME)?.remove();
|
||||
});
|
||||
} else if (this._setting.mouseKey === OPT_MOUSEKEY_PAGEOPEN) {
|
||||
this._tranNodes.forEach((_, node) => {
|
||||
node.querySelector(APP_LCNAME)?.remove();
|
||||
});
|
||||
} else {
|
||||
// 移除鼠标悬停监听
|
||||
window.removeEventListener("keydown", this._handleKeydown);
|
||||
|
||||
@@ -168,11 +168,11 @@ export default function Settings() {
|
||||
/>
|
||||
|
||||
<FormControl size="small">
|
||||
<InputLabel>{i18n("mouseover_translation")}</InputLabel>
|
||||
<InputLabel>{i18n("translate_timing")}</InputLabel>
|
||||
<Select
|
||||
name="mouseKey"
|
||||
value={mouseKey}
|
||||
label={i18n("mouseover_translation")}
|
||||
label={i18n("translate_timing")}
|
||||
onChange={handleChange}
|
||||
>
|
||||
{OPT_MOUSEKEY_ALL.map((item) => (
|
||||
|
||||
Reference in New Issue
Block a user