MCPcopy Create free account
hub / github.com/XIU2/UserScript / mutationObserver

Function mutationObserver

DuckDuckGo-Enhanced.user.js:83–114  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

81
82 // 屏蔽指定域名 链接不携来源
83 function mutationObserver() {
84 const callback = (mutationsList, observer) => {
85 for (const mutation of mutationsList) {
86 for (const target of mutation.addedNodes) {
87 if (target.nodeType != 1) break
88 // 屏蔽指定域名
89 if (target.tagName == 'LI' && target.dataset.layout == 'organic') {
90 Process(target)
91 } else if (target.tagName == 'OL' && target.className == 'react-results--main') {
92 target.childNodes.forEach(li=>{Process(li);})
93 }
94 }
95 }
96 };
97 const observer = new MutationObserver(callback);
98 observer.observe(document, { childList: true, subtree: true });
99
100 function Process(target) {
101 const a = target.querySelector('h2>a,a[data-testid=result-title-a]')
102 if (a) {
103 if (checkDomain(a.href.split('/')[2])) {
104 target.hidden = true
105 } else {
106 // 链接不携来源
107 addRel(target);
108
109 // 添加屏蔽按钮
110 addBlockDomainBtn(target, a, a.href.split('/')[2]);
111 }
112 }
113 }
114 }
115
116
117 // 检查域名是否存在黑名单中

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected