feat: setting: translate page title
This commit is contained in:
@@ -731,4 +731,8 @@ export const I18N = {
|
|||||||
zh: `支持用换行或英文逗号“,”分隔多个KEY轮询调用。`,
|
zh: `支持用换行或英文逗号“,”分隔多个KEY轮询调用。`,
|
||||||
en: `Supports multiple KEY polling calls separated by newlines or English commas ",".`,
|
en: `Supports multiple KEY polling calls separated by newlines or English commas ",".`,
|
||||||
},
|
},
|
||||||
|
translate_page_title: {
|
||||||
|
zh: `是否同时翻译页面标题`,
|
||||||
|
en: `Translate Page Title`,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -298,8 +298,8 @@ export const OPT_STYLE_USE_COLOR = [
|
|||||||
OPT_STYLE_BLOCKQUOTE,
|
OPT_STYLE_BLOCKQUOTE,
|
||||||
];
|
];
|
||||||
|
|
||||||
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_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";
|
||||||
@@ -453,10 +453,11 @@ export const DEFAULT_SETTING = {
|
|||||||
injectWebfix: true, // 是否注入修复补丁
|
injectWebfix: true, // 是否注入修复补丁
|
||||||
detectRemote: false, // 是否使用远程语言检测
|
detectRemote: false, // 是否使用远程语言检测
|
||||||
contextMenus: true, // 是否添加右键菜单
|
contextMenus: true, // 是否添加右键菜单
|
||||||
|
transTitle: false, // 是否同时翻译页面标题
|
||||||
subrulesList: DEFAULT_SUBRULES_LIST, // 订阅列表
|
subrulesList: DEFAULT_SUBRULES_LIST, // 订阅列表
|
||||||
owSubrule: DEFAULT_OW_RULE, // 覆写订阅规则
|
owSubrule: DEFAULT_OW_RULE, // 覆写订阅规则
|
||||||
transApis: DEFAULT_TRANS_APIS, // 翻译接口
|
transApis: DEFAULT_TRANS_APIS, // 翻译接口
|
||||||
mouseKey: OPT_MOUSEKEY_DISABLE, // 鼠标悬停翻译
|
mouseKey: OPT_MOUSEKEY_DISABLE, // 翻译时机/鼠标悬停翻译
|
||||||
shortcuts: DEFAULT_SHORTCUTS, // 快捷键
|
shortcuts: DEFAULT_SHORTCUTS, // 快捷键
|
||||||
inputRule: DEFAULT_INPUT_RULE, // 输入框设置
|
inputRule: DEFAULT_INPUT_RULE, // 输入框设置
|
||||||
tranboxSetting: DEFAULT_TRANBOX_SETTING, // 划词翻译设置
|
tranboxSetting: DEFAULT_TRANBOX_SETTING, // 划词翻译设置
|
||||||
|
|||||||
@@ -309,6 +309,7 @@ export class Translator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 翻译页面标题
|
// 翻译页面标题
|
||||||
|
if (this._setting.transTitle) {
|
||||||
const title = document.title;
|
const title = document.title;
|
||||||
if (!title.endsWith("| ByKT")) {
|
if (!title.endsWith("| ByKT")) {
|
||||||
this._docTitle = title;
|
this._docTitle = title;
|
||||||
@@ -316,6 +317,7 @@ export class Translator {
|
|||||||
document.title = `${trText} | ${title} | ByKT`;
|
document.title = `${trText} | ${title} | ByKT`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_handleMouseover = (e) => {
|
_handleMouseover = (e) => {
|
||||||
@@ -364,7 +366,9 @@ export class Translator {
|
|||||||
|
|
||||||
_unRegister = () => {
|
_unRegister = () => {
|
||||||
// 恢复页面标题
|
// 恢复页面标题
|
||||||
|
if (this._setting.transTitle) {
|
||||||
document.title = this._docTitle;
|
document.title = this._docTitle;
|
||||||
|
}
|
||||||
|
|
||||||
// 解除节点变化监听
|
// 解除节点变化监听
|
||||||
this._mutaObserver.disconnect();
|
this._mutaObserver.disconnect();
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ export default function Settings() {
|
|||||||
mouseKey = OPT_MOUSEKEY_DISABLE,
|
mouseKey = OPT_MOUSEKEY_DISABLE,
|
||||||
detectRemote = false,
|
detectRemote = false,
|
||||||
contextMenus = true,
|
contextMenus = true,
|
||||||
|
transTitle = false,
|
||||||
touchTranslate = 2,
|
touchTranslate = 2,
|
||||||
blacklist = DEFAULT_BLACKLIST.join(",\n"),
|
blacklist = DEFAULT_BLACKLIST.join(",\n"),
|
||||||
disableLangs = [],
|
disableLangs = [],
|
||||||
@@ -183,6 +184,19 @@ export default function Settings() {
|
|||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
|
<FormControl size="small">
|
||||||
|
<InputLabel>{i18n("translate_page_title")}</InputLabel>
|
||||||
|
<Select
|
||||||
|
name="transTitle"
|
||||||
|
value={transTitle}
|
||||||
|
label={i18n("translate_page_title")}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
<MenuItem value={false}>{i18n("disable")}</MenuItem>
|
||||||
|
<MenuItem value={true}>{i18n("enable")}</MenuItem>
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
<FormControl size="small">
|
<FormControl size="small">
|
||||||
<InputLabel>{i18n("touch_translate_shortcut")}</InputLabel>
|
<InputLabel>{i18n("touch_translate_shortcut")}</InputLabel>
|
||||||
<Select
|
<Select
|
||||||
|
|||||||
Reference in New Issue
Block a user