Skip to content

Commit ad7ba41

Browse files
committed
修复 因网页变动导致失效的功能
1 parent 93d98f9 commit ad7ba41

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

DuckDuckGo-Enhanced.user.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @name:zh-CN DuckDuckGo 增强
44
// @name:zh-TW DuckDuckGo 增強
55
// @name:en DuckDuckGo Enhancements
6-
// @version 1.0.2
6+
// @version 1.0.3
77
// @author X.I.U
88
// @description 屏蔽指定域名、修复图标加载、链接不携来源、快捷回到顶部(右键两侧空白处)
99
// @description:zh-CN 简单有效的全网通用护眼模式(夜间模式、暗黑模式、深色模式)
@@ -56,9 +56,12 @@
5656
};
5757

5858

59-
document.documentElement.appendChild(document.createElement('style')).textContent = '.blockDomainBtn {padding: 0 8px !important; font-size: 12px !important; line-height: normal !important; margin-left: 10px !important; border-radius: 3px !important; vertical-align: top !important; opacity: 0.4 !important; top: 3px; cursor: cell;} .result.result--sep--hr {display: none;} a[data-testid="result-title-a"]{display: inline-block}';
59+
document.documentElement.appendChild(document.createElement('style')).textContent = `
60+
.blockDomainBtn {padding: 0 6px !important; font-size: 12px !important; line-height: normal !important; margin-left: 6px !important; border-radius: 3px !important; vertical-align: top !important; opacity: 0.4 !important; top: 3px; cursor: cell;}
61+
.result.result--sep--hr {display: none;}
62+
a[data-testid="result-title-a"]{display: inline-block}`
6063
mutationObserver(); // 屏蔽指定域名 + 修复图标加载 + 链接不携来源
61-
backToTop(); // 快捷回到顶部
64+
setTimeout(backToTop, 500); // 快捷回到顶部
6265

6366

6467
// 自定义屏蔽指定域名
@@ -82,19 +85,12 @@
8285
for (const mutation of mutationsList) {
8386
for (const target of mutation.addedNodes) {
8487
if (target.nodeType != 1) break
85-
88+
//console.log(target)
8689
// 屏蔽指定域名
87-
if (target.dataset.nrn === 'result') {
88-
const a=target.querySelector('h2>a,a[data-testid="result-title-a]"')
89-
if (a && checkDomain(a.href.split('/')[2])) {
90-
target.remove(); break;
91-
} else {
92-
// 链接不携来源
93-
addRel(target);
94-
95-
// 添加屏蔽按钮
96-
addBlockDomainBtn(target, a, a.href.split('/')[2]);
97-
}
90+
if (target.tagName == 'LI' && target.dataset.layout == 'organic') {
91+
Process(target)
92+
} else if (target.tagName == 'OL' && target.className == 'react-results--main') {
93+
target.childNodes.forEach(li=>{Process(li)})
9894
}
9995
// 修复图标加载
10096
//let img = target.querySelector('img.result__icon__img[data-src]'); // 寻找图标元素
@@ -104,6 +100,19 @@
104100
};
105101
const observer = new MutationObserver(callback);
106102
observer.observe(document, { childList: true, subtree: true });
103+
104+
function Process(target) {
105+
const a = target.querySelector('h2>a,a[data-testid="result-title-a]"')
106+
if (a && checkDomain(a.href.split('/')[2])) {
107+
target.remove();
108+
} else {
109+
// 链接不携来源
110+
addRel(target);
111+
112+
// 添加屏蔽按钮
113+
addBlockDomainBtn(target, a, a.href.split('/')[2]);
114+
}
115+
}
107116
}
108117

109118

@@ -145,8 +154,9 @@
145154
// 快捷回到顶部(右键两侧空白处)
146155
function backToTop() {
147156
if (!GM_getValue('menu_backToTop')) return
148-
document.querySelectorAll('#web_content_wrapper, #web_content_wrapper > .cw, #links_wrapper').forEach(ele => {
157+
document.querySelectorAll('#react-layout>div, #react-layout>div>div, section[data-testid=sidebar]').forEach(ele => {
149158
ele.oncontextmenu = function(e) {
159+
//console.log(e.target, this)
150160
if (e.target == this) {
151161
e.preventDefault();
152162
window.scrollTo(0,0);

0 commit comments

Comments
 (0)