|
3 | 3 | // @name:zh-CN DuckDuckGo 增强 |
4 | 4 | // @name:zh-TW DuckDuckGo 增強 |
5 | 5 | // @name:en DuckDuckGo Enhancements |
6 | | -// @version 1.0.1 |
| 6 | +// @version 1.0.2 |
7 | 7 | // @author X.I.U |
8 | 8 | // @description 屏蔽指定域名、修复图标加载、链接不携来源、快捷回到顶部(右键两侧空白处) |
9 | 9 | // @description:zh-CN 简单有效的全网通用护眼模式(夜间模式、暗黑模式、深色模式) |
|
18 | 18 | // @grant GM_setValue |
19 | 19 | // @grant GM_notification |
20 | 20 | // @license GPL-3.0 License |
21 | | -// @run-at document-end |
| 21 | +// @run-at document-idle |
22 | 22 | // @namespace https://github.com/XIU2/UserScript |
23 | 23 | // @supportURL https://github.com/XIU2/UserScript |
24 | 24 | // @homepageURL https://github.com/XIU2/UserScript |
|
56 | 56 | }; |
57 | 57 |
|
58 | 58 |
|
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;}'; |
| 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}'; |
60 | 60 | mutationObserver(); // 屏蔽指定域名 + 修复图标加载 + 链接不携来源 |
61 | 61 | backToTop(); // 快捷回到顶部 |
62 | 62 |
|
|
84 | 84 | if (target.nodeType != 1) break |
85 | 85 |
|
86 | 86 | // 屏蔽指定域名 |
87 | | - if (target.dataset.domain && checkDomain(target.dataset.domain)) {target.remove(); break;} |
88 | | - |
| 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 | + } |
| 98 | + } |
89 | 99 | // 修复图标加载 |
90 | | - let img = target.querySelector('img.result__icon__img[data-src]'); // 寻找图标元素 |
91 | | - if (img && !img.src) img.src = img.dataset.src |
92 | | - |
93 | | - // 链接不携来源 |
94 | | - addRel(target); |
95 | | - |
96 | | - // 添加屏蔽按钮 |
97 | | - addBlockDomainBtn(target, target.dataset.domain); |
| 100 | + //let img = target.querySelector('img.result__icon__img[data-src]'); // 寻找图标元素 |
| 101 | + //if (img && !img.src) img.src = img.dataset.src |
98 | 102 | } |
99 | 103 | } |
100 | 104 | }; |
|
120 | 124 |
|
121 | 125 |
|
122 | 126 | // 添加屏蔽按钮 |
123 | | - function addBlockDomainBtn(doc, domain) { |
| 127 | + function addBlockDomainBtn(doc, toElement, domain) { |
124 | 128 | if (!GM_getValue('menu_blockDomainBtn')) return |
125 | | - let toElement = doc.querySelector('a.result__url'); |
| 129 | + //let toElement = doc.querySelector('a.result__url'); |
126 | 130 | if (toElement) { |
127 | 131 | toElement.insertAdjacentHTML('afterend', `<button class="btn blockDomainBtn" data-domain="${domain}" title="点击在搜索结果中屏蔽 [ ${domain} ] 域名">屏蔽</button>`); |
128 | 132 | doc.querySelector('button.blockDomainBtn').addEventListener('click', function(e) { |
|
132 | 136 | blockDomain.push(e.target.dataset.domain) |
133 | 137 | GM_setValue('menu_blockDomain', blockDomain); |
134 | 138 | // 隐藏该域名的所有搜索结果 |
135 | | - document.querySelectorAll(`#links > div[data-domain="${e.target.dataset.domain}"]`).forEach(function(one){one.style.display = 'none'}) |
| 139 | + document.querySelectorAll(`button[data-domain="${e.target.dataset.domain}"].blockDomainBtn`).forEach(function(one){one.parentElement.parentElement.parentElement.parentElement.remove();}) |
136 | 140 | }); |
137 | 141 | } |
138 | 142 | } |
|
0 commit comments