feat: move selected translation switch from setting to rule
This commit is contained in:
@@ -135,15 +135,18 @@ async function showFab(translator) {
|
|||||||
* @param {*} param0
|
* @param {*} param0
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function showTransbox({
|
function showTransbox(
|
||||||
contextMenuType,
|
{
|
||||||
tranboxSetting = DEFAULT_TRANBOX_SETTING,
|
contextMenuType,
|
||||||
transApis,
|
tranboxSetting = DEFAULT_TRANBOX_SETTING,
|
||||||
darkMode,
|
transApis,
|
||||||
uiLang,
|
darkMode,
|
||||||
langDetector,
|
uiLang,
|
||||||
}) {
|
langDetector,
|
||||||
if (!tranboxSetting?.transOpen) {
|
},
|
||||||
|
{ transSelected }
|
||||||
|
) {
|
||||||
|
if (transSelected === "false") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,7 +254,7 @@ export async function run(isUserscript = false) {
|
|||||||
inputTranslate(setting);
|
inputTranslate(setting);
|
||||||
|
|
||||||
// 划词翻译
|
// 划词翻译
|
||||||
showTransbox(setting);
|
showTransbox(setting, rule);
|
||||||
|
|
||||||
// 浮球按钮
|
// 浮球按钮
|
||||||
await showFab(translator);
|
await showFab(translator);
|
||||||
|
|||||||
@@ -962,4 +962,8 @@ export const I18N = {
|
|||||||
zh: `是否禁用`,
|
zh: `是否禁用`,
|
||||||
en: `Is Disabled`,
|
en: `Is Disabled`,
|
||||||
},
|
},
|
||||||
|
translate_selected: {
|
||||||
|
zh: `是否启用划词翻译`,
|
||||||
|
en: `If translate selected`,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -463,6 +463,7 @@ export const GLOBLA_RULE = {
|
|||||||
transTiming: OPT_TIMING_PAGESCROLL, // 翻译时机/鼠标悬停翻译
|
transTiming: OPT_TIMING_PAGESCROLL, // 翻译时机/鼠标悬停翻译
|
||||||
transTag: DEFAULT_TRANS_TAG, // 译文元素标签
|
transTag: DEFAULT_TRANS_TAG, // 译文元素标签
|
||||||
transTitle: "false", // 是否同时翻译页面标题
|
transTitle: "false", // 是否同时翻译页面标题
|
||||||
|
transSelected: "true", // 是否启用划词翻译
|
||||||
detectRemote: "false", // 是否使用远程语言检测
|
detectRemote: "false", // 是否使用远程语言检测
|
||||||
skipLangs: [], // 不翻译的语言
|
skipLangs: [], // 不翻译的语言
|
||||||
fixerSelector: "", // 修复函数选择器
|
fixerSelector: "", // 修复函数选择器
|
||||||
@@ -501,7 +502,7 @@ export const OPT_TRANBOX_TRIGGER_ALL = [
|
|||||||
];
|
];
|
||||||
export const DEFAULT_TRANBOX_SHORTCUT = ["AltLeft", "KeyS"];
|
export const DEFAULT_TRANBOX_SHORTCUT = ["AltLeft", "KeyS"];
|
||||||
export const DEFAULT_TRANBOX_SETTING = {
|
export const DEFAULT_TRANBOX_SETTING = {
|
||||||
transOpen: true,
|
// transOpen: true, // 是否启用划词翻译(作废,移至rule)
|
||||||
translator: OPT_TRANS_MICROSOFT,
|
translator: OPT_TRANS_MICROSOFT,
|
||||||
fromLang: "auto",
|
fromLang: "auto",
|
||||||
toLang: "zh-CN",
|
toLang: "zh-CN",
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ export const DEFAULT_RULE = {
|
|||||||
transTiming: GLOBAL_KEY, // 翻译时机/鼠标悬停翻译
|
transTiming: GLOBAL_KEY, // 翻译时机/鼠标悬停翻译
|
||||||
transTag: GLOBAL_KEY, // 译文元素标签
|
transTag: GLOBAL_KEY, // 译文元素标签
|
||||||
transTitle: GLOBAL_KEY, // 是否同时翻译页面标题
|
transTitle: GLOBAL_KEY, // 是否同时翻译页面标题
|
||||||
|
transSelected: GLOBAL_KEY, // 是否启用划词翻译
|
||||||
detectRemote: GLOBAL_KEY, // 是否使用远程语言检测
|
detectRemote: GLOBAL_KEY, // 是否使用远程语言检测
|
||||||
skipLangs: [], // 不翻译的语言
|
skipLangs: [], // 不翻译的语言
|
||||||
fixerSelector: "", // 修复函数选择器
|
fixerSelector: "", // 修复函数选择器
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ export const matchRule = async (
|
|||||||
"transTiming",
|
"transTiming",
|
||||||
"transTag",
|
"transTag",
|
||||||
"transTitle",
|
"transTitle",
|
||||||
|
"transSelected",
|
||||||
"detectRemote",
|
"detectRemote",
|
||||||
"fixerFunc",
|
"fixerFunc",
|
||||||
].forEach((key) => {
|
].forEach((key) => {
|
||||||
@@ -161,6 +162,7 @@ export const checkRules = (rules) => {
|
|||||||
transTiming,
|
transTiming,
|
||||||
transTag,
|
transTag,
|
||||||
transTitle,
|
transTitle,
|
||||||
|
transSelected,
|
||||||
detectRemote,
|
detectRemote,
|
||||||
skipLangs,
|
skipLangs,
|
||||||
fixerSelector,
|
fixerSelector,
|
||||||
@@ -188,6 +190,7 @@ export const checkRules = (rules) => {
|
|||||||
transTiming: matchValue([GLOBAL_KEY, ...OPT_TIMING_ALL], transTiming),
|
transTiming: matchValue([GLOBAL_KEY, ...OPT_TIMING_ALL], transTiming),
|
||||||
transTag: matchValue([GLOBAL_KEY, "span", "font"], transTag),
|
transTag: matchValue([GLOBAL_KEY, "span", "font"], transTag),
|
||||||
transTitle: matchValue([GLOBAL_KEY, "true", "false"], transTitle),
|
transTitle: matchValue([GLOBAL_KEY, "true", "false"], transTitle),
|
||||||
|
transSelected: matchValue([GLOBAL_KEY, "true", "false"], transSelected),
|
||||||
detectRemote: matchValue([GLOBAL_KEY, "true", "false"], detectRemote),
|
detectRemote: matchValue([GLOBAL_KEY, "true", "false"], detectRemote),
|
||||||
skipLangs: type(skipLangs) === "array" ? skipLangs : [],
|
skipLangs: type(skipLangs) === "array" ? skipLangs : [],
|
||||||
fixerSelector: type(fixerSelector) === "string" ? fixerSelector : "",
|
fixerSelector: type(fixerSelector) === "string" ? fixerSelector : "",
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ function RuleFields({ rule, rules, setShow, setKeyword }) {
|
|||||||
transTiming = OPT_TIMING_PAGESCROLL,
|
transTiming = OPT_TIMING_PAGESCROLL,
|
||||||
transTag = DEFAULT_TRANS_TAG,
|
transTag = DEFAULT_TRANS_TAG,
|
||||||
transTitle = "false",
|
transTitle = "false",
|
||||||
|
transSelected = "true",
|
||||||
detectRemote = "false",
|
detectRemote = "false",
|
||||||
skipLangs = [],
|
skipLangs = [],
|
||||||
fixerSelector = "",
|
fixerSelector = "",
|
||||||
@@ -413,6 +414,22 @@ function RuleFields({ rule, rules, setShow, setKeyword }) {
|
|||||||
<MenuItem value={"true"}>{i18n("enable")}</MenuItem>
|
<MenuItem value={"true"}>{i18n("enable")}</MenuItem>
|
||||||
</TextField>
|
</TextField>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid item xs={12} sm={6} md={3} lg={2}>
|
||||||
|
<TextField
|
||||||
|
select
|
||||||
|
size="small"
|
||||||
|
fullWidth
|
||||||
|
name="transSelected"
|
||||||
|
value={transSelected}
|
||||||
|
label={i18n("translate_selected")}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
{GlobalItem}
|
||||||
|
<MenuItem value={"false"}>{i18n("disable")}</MenuItem>
|
||||||
|
<MenuItem value={"true"}>{i18n("enable")}</MenuItem>
|
||||||
|
</TextField>
|
||||||
|
</Grid>
|
||||||
<Grid item xs={12} sm={6} md={3} lg={2}>
|
<Grid item xs={12} sm={6} md={3} lg={2}>
|
||||||
<TextField
|
<TextField
|
||||||
select
|
select
|
||||||
|
|||||||
Reference in New Issue
Block a user