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