fix: ignore selector
This commit is contained in:
@@ -97,7 +97,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 = "button, footer, pre, mark, nav";
|
export const DEFAULT_IGNORE_SELECTOR = "button, footer, pre, mark, nav";
|
||||||
export const DEFAULT_KEEP_SELECTOR = `a:has(code)`;
|
export const DEFAULT_KEEP_SELECTOR = `code, cite, math, .math, a:has(code)`;
|
||||||
export const DEFAULT_RULE = {
|
export const DEFAULT_RULE = {
|
||||||
pattern: "", // 匹配网址
|
pattern: "", // 匹配网址
|
||||||
selector: "", // 选择器
|
selector: "", // 选择器
|
||||||
|
|||||||
@@ -248,11 +248,11 @@ export class Translator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 内置忽略元素
|
// 内置忽略元素
|
||||||
static BUILTIN_IGNORE_SELECTOR = `abbr, address, area, audio, br, canvas, code,
|
static BUILTIN_IGNORE_SELECTOR = `address, area, audio, br, canvas,
|
||||||
data, datalist, dfn, embed, head, iframe, img, input, kbd, noscript, map,
|
data, datalist, embed, head, iframe, input, noscript, map,
|
||||||
object, option, output, param, picture, progress,
|
object, option, param, picture, progress,
|
||||||
samp, select, script, style, sub, sup, svg, track, time, textarea, template,
|
select, script, style, track, textarea, template,
|
||||||
var, video, wbr, .notranslate, [contenteditable], [translate='no'],
|
video, wbr, .notranslate, [contenteditable], [translate='no'],
|
||||||
${APP_LCNAME}, #${APP_CONSTS.fabID}, #${APP_CONSTS.boxID},
|
${APP_LCNAME}, #${APP_CONSTS.fabID}, #${APP_CONSTS.boxID},
|
||||||
.${APP_CONSTS.fabID}_warpper, .${APP_CONSTS.boxID}_warpper`;
|
.${APP_CONSTS.fabID}_warpper, .${APP_CONSTS.boxID}_warpper`;
|
||||||
|
|
||||||
@@ -772,6 +772,7 @@ export class Translator {
|
|||||||
#scanNode(rootNode) {
|
#scanNode(rootNode) {
|
||||||
if (
|
if (
|
||||||
!Translator.isElementOrFragment(rootNode) ||
|
!Translator.isElementOrFragment(rootNode) ||
|
||||||
|
rootNode.matches?.(this.#rule.keepSelector) ||
|
||||||
rootNode.matches?.(this.#ignoreSelector)
|
rootNode.matches?.(this.#ignoreSelector)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
@@ -1028,6 +1029,7 @@ export class Translator {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
Translator.TAGS.BREAK_LINE.has(node.nodeName) ||
|
Translator.TAGS.BREAK_LINE.has(node.nodeName) ||
|
||||||
|
node.matches?.(this.#ignoreSelector) ||
|
||||||
node.nodeName === this.#translationTagName
|
node.nodeName === this.#translationTagName
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
@@ -1271,6 +1273,7 @@ export class Translator {
|
|||||||
if (
|
if (
|
||||||
Translator.TAGS.REPLACE.has(node.tagName) ||
|
Translator.TAGS.REPLACE.has(node.tagName) ||
|
||||||
node.matches(this.#rule.keepSelector) ||
|
node.matches(this.#rule.keepSelector) ||
|
||||||
|
node.matches(this.#ignoreSelector) ||
|
||||||
!node.textContent.trim()
|
!node.textContent.trim()
|
||||||
) {
|
) {
|
||||||
if (node.tagName === "IMG" || node.tagName === "SVG") {
|
if (node.tagName === "IMG" || node.tagName === "SVG") {
|
||||||
|
|||||||
Reference in New Issue
Block a user