Skip to content

Commit

Permalink
ignoreMutationSelectorsignoreSelectors转为字符串形式,使用.closest()和`.…
Browse files Browse the repository at this point in the history
…matches()`方法进行匹配
  • Loading branch information
maboloshi committed Feb 8, 2025
1 parent 8436b92 commit 5eef17c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions main.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -136,10 +136,8 @@
})
// 过滤需要忽略的突变节点
.filter(node =>
!pageConfig.ignoreMutationSelectors.some(selector =>
// 检查节点是否在忽略选择器的父元素内
node.parentElement?.closest(selector)
)
// 剔除节点在忽略选择器的父元素内
!node.parentElement?.closest(pageConfig.ignoreMutationSelectors)
)
// 处理每个变化
.forEach(node =>
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5eef17c

Please sign in to comment.