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