Skip to content

Commit

Permalink
加强:watchUpdate 函数新增节点文本更新的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
maboloshi committed Aug 23, 2023
1 parent e9ead60 commit 19bcd93
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions main(greasyfork).user.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@

if (page) {
// 使用 filter 方法对 mutations 数组进行筛选,
// 返回 `节点增加 或 属性更改的 mutation` 组成的新数组 filteredMutations。
const filteredMutations = mutations.filter(mutation => mutation.addedNodes.length > 0 || mutation.type === 'attributes');
// 返回 `节点增加、文本更新 或 属性更改的 mutation` 组成的新数组 filteredMutations。
const filteredMutations = mutations.filter(mutation => mutation.addedNodes.length > 0 || mutation.type === 'attributes' || mutation.type === 'characterData');

// 处理每个变化
filteredMutations.forEach(mutation => traverseNode(mutation.target));
Expand All @@ -78,6 +78,7 @@

// 配置 MutationObserver
const config = {
characterData: true,
subtree: true,
childList: true,
attributeFilter: ['value', 'placeholder', 'aria-label', 'data-confirm'], // 仅观察特定属性变化
Expand Down
5 changes: 3 additions & 2 deletions main.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@

if (page) {
// 使用 filter 方法对 mutations 数组进行筛选,
// 返回 `节点增加 或 属性更改的 mutation` 组成的新数组 filteredMutations。
const filteredMutations = mutations.filter(mutation => mutation.addedNodes.length > 0 || mutation.type === 'attributes');
// 返回 `节点增加、文本更新 或 属性更改的 mutation` 组成的新数组 filteredMutations。
const filteredMutations = mutations.filter(mutation => mutation.addedNodes.length > 0 || mutation.type === 'attributes' || mutation.type === 'characterData');

// 处理每个变化
filteredMutations.forEach(mutation => traverseNode(mutation.target));
Expand All @@ -78,6 +78,7 @@

// 配置 MutationObserver
const config = {
characterData: true,
subtree: true,
childList: true,
attributeFilter: ['value', 'placeholder', 'aria-label', 'data-confirm'], // 仅观察特定属性变化
Expand Down

0 comments on commit 19bcd93

Please sign in to comment.