|
3 | 3 | // @name:zh-CN DuckDuckGo 增强 |
4 | 4 | // @name:zh-TW DuckDuckGo 增強 |
5 | 5 | // @name:en DuckDuckGo Enhancements |
6 | | -// @version 1.0.2 |
| 6 | +// @version 1.0.3 |
7 | 7 | // @author X.I.U |
8 | 8 | // @description 屏蔽指定域名、修复图标加载、链接不携来源、快捷回到顶部(右键两侧空白处) |
9 | 9 | // @description:zh-CN 简单有效的全网通用护眼模式(夜间模式、暗黑模式、深色模式) |
|
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;} 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}` |
60 | 63 | mutationObserver(); // 屏蔽指定域名 + 修复图标加载 + 链接不携来源 |
61 | | - backToTop(); // 快捷回到顶部 |
| 64 | + setTimeout(backToTop, 500); // 快捷回到顶部 |
62 | 65 |
|
63 | 66 |
|
64 | 67 | // 自定义屏蔽指定域名 |
|
82 | 85 | for (const mutation of mutationsList) { |
83 | 86 | for (const target of mutation.addedNodes) { |
84 | 87 | if (target.nodeType != 1) break |
85 | | - |
| 88 | + //console.log(target) |
86 | 89 | // 屏蔽指定域名 |
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)}) |
98 | 94 | } |
99 | 95 | // 修复图标加载 |
100 | 96 | //let img = target.querySelector('img.result__icon__img[data-src]'); // 寻找图标元素 |
|
104 | 100 | }; |
105 | 101 | const observer = new MutationObserver(callback); |
106 | 102 | 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 | + } |
107 | 116 | } |
108 | 117 |
|
109 | 118 |
|
|
145 | 154 | // 快捷回到顶部(右键两侧空白处) |
146 | 155 | function backToTop() { |
147 | 156 | 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 => { |
149 | 158 | ele.oncontextmenu = function(e) { |
| 159 | + //console.log(e.target, this) |
150 | 160 | if (e.target == this) { |
151 | 161 | e.preventDefault(); |
152 | 162 | window.scrollTo(0,0); |
|
0 commit comments