feat: terms style
This commit is contained in:
@@ -718,6 +718,11 @@ export const I18N = {
|
|||||||
en: `Selector Style`,
|
en: `Selector Style`,
|
||||||
zh_TW: `選擇器節點樣式`,
|
zh_TW: `選擇器節點樣式`,
|
||||||
},
|
},
|
||||||
|
terms_style: {
|
||||||
|
zh: `专业术语样式`,
|
||||||
|
en: `Terms Style`,
|
||||||
|
zh_TW: `專業術語樣式`,
|
||||||
|
},
|
||||||
selector_style_helper: {
|
selector_style_helper: {
|
||||||
zh: `开启翻译时注入。`,
|
zh: `开启翻译时注入。`,
|
||||||
en: `It is injected when translation is turned on.`,
|
en: `It is injected when translation is turned on.`,
|
||||||
|
|||||||
@@ -78,8 +78,7 @@ background: linear-gradient(
|
|||||||
|
|
||||||
export const DEFAULT_SELECTOR =
|
export const DEFAULT_SELECTOR =
|
||||||
"h1, h2, h3, h4, h5, h6, li, p, dd, blockquote, figcaption, label, legend";
|
"h1, h2, h3, h4, h5, h6, li, p, dd, blockquote, figcaption, label, legend";
|
||||||
export const DEFAULT_IGNORE_SELECTOR =
|
export const DEFAULT_IGNORE_SELECTOR = "aside, button, footer, pre, mark, nav";
|
||||||
"aside, button, footer, pre, mark, nav";
|
|
||||||
export const DEFAULT_KEEP_SELECTOR = `a:has(code)`;
|
export const DEFAULT_KEEP_SELECTOR = `a:has(code)`;
|
||||||
export const DEFAULT_RULE = {
|
export const DEFAULT_RULE = {
|
||||||
pattern: "", // 匹配网址
|
pattern: "", // 匹配网址
|
||||||
@@ -94,6 +93,7 @@ export const DEFAULT_RULE = {
|
|||||||
transOpen: GLOBAL_KEY, // 开启翻译
|
transOpen: GLOBAL_KEY, // 开启翻译
|
||||||
bgColor: "", // 译文颜色
|
bgColor: "", // 译文颜色
|
||||||
textDiyStyle: "", // 自定义译文样式
|
textDiyStyle: "", // 自定义译文样式
|
||||||
|
termsStyle: "", // 专业术语样式
|
||||||
selectStyle: "", // 选择器节点样式
|
selectStyle: "", // 选择器节点样式
|
||||||
parentStyle: "", // 选择器父节点样式
|
parentStyle: "", // 选择器父节点样式
|
||||||
grandStyle: "", // 选择器父节点样式
|
grandStyle: "", // 选择器父节点样式
|
||||||
@@ -132,6 +132,7 @@ export const GLOBLA_RULE = {
|
|||||||
transOpen: "false", // 开启翻译
|
transOpen: "false", // 开启翻译
|
||||||
bgColor: "", // 译文颜色
|
bgColor: "", // 译文颜色
|
||||||
textDiyStyle: DEFAULT_DIY_STYLE, // 自定义译文样式
|
textDiyStyle: DEFAULT_DIY_STYLE, // 自定义译文样式
|
||||||
|
termsStyle: "font-weight: bold;", // 专业术语样式
|
||||||
selectStyle: DEFAULT_SELECT_STYLE, // 选择器节点样式
|
selectStyle: DEFAULT_SELECT_STYLE, // 选择器节点样式
|
||||||
parentStyle: DEFAULT_SELECT_STYLE, // 选择器父节点样式
|
parentStyle: DEFAULT_SELECT_STYLE, // 选择器父节点样式
|
||||||
grandStyle: DEFAULT_SELECT_STYLE, // 选择器祖节点样式
|
grandStyle: DEFAULT_SELECT_STYLE, // 选择器祖节点样式
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ export const matchRule = async (href, { injectRules, subrulesList }) => {
|
|||||||
"ignoreSelector",
|
"ignoreSelector",
|
||||||
"terms",
|
"terms",
|
||||||
"aiTerms",
|
"aiTerms",
|
||||||
|
"termsStyle",
|
||||||
"selectStyle",
|
"selectStyle",
|
||||||
"parentStyle",
|
"parentStyle",
|
||||||
"grandStyle",
|
"grandStyle",
|
||||||
@@ -136,6 +137,7 @@ export const checkRules = (rules) => {
|
|||||||
ignoreSelector,
|
ignoreSelector,
|
||||||
terms,
|
terms,
|
||||||
aiTerms,
|
aiTerms,
|
||||||
|
termsStyle,
|
||||||
selectStyle,
|
selectStyle,
|
||||||
parentStyle,
|
parentStyle,
|
||||||
grandStyle,
|
grandStyle,
|
||||||
@@ -170,6 +172,7 @@ export const checkRules = (rules) => {
|
|||||||
ignoreSelector: type(ignoreSelector) === "string" ? ignoreSelector : "",
|
ignoreSelector: type(ignoreSelector) === "string" ? ignoreSelector : "",
|
||||||
terms: type(terms) === "string" ? terms : "",
|
terms: type(terms) === "string" ? terms : "",
|
||||||
aiTerms: type(aiTerms) === "string" ? aiTerms : "",
|
aiTerms: type(aiTerms) === "string" ? aiTerms : "",
|
||||||
|
termsStyle: type(termsStyle) === "string" ? termsStyle : "",
|
||||||
selectStyle: type(selectStyle) === "string" ? selectStyle : "",
|
selectStyle: type(selectStyle) === "string" ? selectStyle : "",
|
||||||
parentStyle: type(parentStyle) === "string" ? parentStyle : "",
|
parentStyle: type(parentStyle) === "string" ? parentStyle : "",
|
||||||
grandStyle: type(grandStyle) === "string" ? grandStyle : "",
|
grandStyle: type(grandStyle) === "string" ? grandStyle : "",
|
||||||
|
|||||||
@@ -959,6 +959,7 @@ export class Translator {
|
|||||||
transStartHook,
|
transStartHook,
|
||||||
transEndHook,
|
transEndHook,
|
||||||
transOnly,
|
transOnly,
|
||||||
|
termsStyle,
|
||||||
selectStyle,
|
selectStyle,
|
||||||
parentStyle,
|
parentStyle,
|
||||||
grandStyle,
|
grandStyle,
|
||||||
@@ -988,8 +989,10 @@ export class Translator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [processedString, placeholderMap] =
|
const [processedString, placeholderMap] = this.#serializeForTranslation(
|
||||||
this.#serializeForTranslation(nodes);
|
nodes,
|
||||||
|
termsStyle
|
||||||
|
);
|
||||||
// console.log("processedString", processedString);
|
// console.log("processedString", processedString);
|
||||||
if (this.#isInvalidText(processedString)) return;
|
if (this.#isInvalidText(processedString)) return;
|
||||||
|
|
||||||
@@ -1078,7 +1081,7 @@ export class Translator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理节点转为翻译字符串
|
// 处理节点转为翻译字符串
|
||||||
#serializeForTranslation(nodes) {
|
#serializeForTranslation(nodes, termsStyle) {
|
||||||
let replaceCounter = 0; // {{n}}
|
let replaceCounter = 0; // {{n}}
|
||||||
let wrapCounter = 0; // <tagn>
|
let wrapCounter = 0; // <tagn>
|
||||||
const placeholderMap = new Map();
|
const placeholderMap = new Map();
|
||||||
@@ -1118,7 +1121,7 @@ export class Translator {
|
|||||||
const termValue = this.#termValues[matchedIndex];
|
const termValue = this.#termValues[matchedIndex];
|
||||||
|
|
||||||
return pushReplace(
|
return pushReplace(
|
||||||
`<i class="${Translator.KISS_CLASS.term}">${termValue || fullMatch}</i>`
|
`<i class="${Translator.KISS_CLASS.term}" style="${termsStyle}">${termValue || fullMatch}</i>`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ function RuleFields({ rule, rules, setShow, setKeyword }) {
|
|||||||
ignoreSelector = "",
|
ignoreSelector = "",
|
||||||
terms = "",
|
terms = "",
|
||||||
aiTerms = "",
|
aiTerms = "",
|
||||||
|
termsStyle = "",
|
||||||
selectStyle = "",
|
selectStyle = "",
|
||||||
parentStyle = "",
|
parentStyle = "",
|
||||||
grandStyle = "",
|
grandStyle = "",
|
||||||
@@ -547,10 +548,19 @@ function RuleFields({ rule, rules, setShow, setKeyword }) {
|
|||||||
maxRows={10}
|
maxRows={10}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
size="small"
|
||||||
|
label={i18n("terms_style")}
|
||||||
|
name="termsStyle"
|
||||||
|
value={termsStyle}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={handleChange}
|
||||||
|
maxRows={10}
|
||||||
|
multiline
|
||||||
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
size="small"
|
size="small"
|
||||||
label={i18n("selector_style")}
|
label={i18n("selector_style")}
|
||||||
helperText={i18n("selector_style_helper")}
|
|
||||||
name="selectStyle"
|
name="selectStyle"
|
||||||
value={selectStyle}
|
value={selectStyle}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
@@ -561,7 +571,6 @@ function RuleFields({ rule, rules, setShow, setKeyword }) {
|
|||||||
<TextField
|
<TextField
|
||||||
size="small"
|
size="small"
|
||||||
label={i18n("selector_parent_style")}
|
label={i18n("selector_parent_style")}
|
||||||
helperText={i18n("selector_style_helper")}
|
|
||||||
name="parentStyle"
|
name="parentStyle"
|
||||||
value={parentStyle}
|
value={parentStyle}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
@@ -572,7 +581,6 @@ function RuleFields({ rule, rules, setShow, setKeyword }) {
|
|||||||
<TextField
|
<TextField
|
||||||
size="small"
|
size="small"
|
||||||
label={i18n("selector_grand_style")}
|
label={i18n("selector_grand_style")}
|
||||||
helperText={i18n("selector_style_helper")}
|
|
||||||
name="grandStyle"
|
name="grandStyle"
|
||||||
value={grandStyle}
|
value={grandStyle}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
|||||||
Reference in New Issue
Block a user