From 5eef17ca644023c876dc8bb449e333ccc2396482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=99=E6=BC=A0=E4=B9=8B=E5=AD=90?= <7850715+maboloshi@users.noreply.github.com> Date: Sat, 8 Feb 2025 10:54:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86`ignoreMutationSelectors`=E5=92=8C`ign?= =?UTF-8?q?oreSelectors`=E8=BD=AC=E4=B8=BA=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E5=BD=A2=E5=BC=8F,=E4=BD=BF=E7=94=A8`.closest()`=E5=92=8C`.mat?= =?UTF-8?q?ches()`=E6=96=B9=E6=B3=95=E8=BF=9B=E8=A1=8C=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.user.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/main.user.js b/main.user.js index 447333c1b..9eb5a1e52 100644 --- a/main.user.js +++ b/main.user.js @@ -81,17 +81,17 @@ ...I18N[CONFIG.LANG].public.regexp, ...(I18N[CONFIG.LANG][pageType]?.regexp || []) ], - // 忽略突变元素选择器 + // 忽略突变元素选择器(字符串) ignoreMutationSelectors: [ ...I18N.conf.ignoreMutationSelectorPage['*'], ...(I18N.conf.ignoreMutationSelectorPage[pageType] || []) - ], - // 忽略元素选择器规则 + ].join(', '), + // 忽略元素选择器规则(字符串) ignoreSelectors: [ ...I18N.conf.ignoreSelectorPage['*'], ...(I18N.conf.ignoreSelectorPage[pageType] || []) - ], - // 字符数据监视开启规则 + ].join(', '), + // 字符数据监视开启规则(布尔值) characterData: I18N.conf.characterDataPage.includes(pageType), // CSS 选择器规则 tranSelectors: [ @@ -136,10 +136,8 @@ }) // 过滤需要忽略的突变节点 .filter(node => - !pageConfig.ignoreMutationSelectors.some(selector => - // 检查节点是否在忽略选择器的父元素内 - node.parentElement?.closest(selector) - ) + // 剔除节点在忽略选择器的父元素内 + !node.parentElement?.closest(pageConfig.ignoreMutationSelectors) ) // 处理每个变化 .forEach(node => @@ -174,7 +172,7 @@ return; // 文本节点没有子节点,直接返回 } - const skipNode = node => pageConfig.ignoreSelectors.some(selector => node.matches?.(selector)); + const skipNode = node => node.matches?.(pageConfig.ignoreSelectors); const treeWalker = document.createTreeWalker( rootNode, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT,