// ==UserScript== // @name DuckDuckGo 增强 // @name:zh-CN DuckDuckGo 增强 // @name:zh-TW DuckDuckGo 增強 // @name:en DuckDuckGo Enhancements // @version 1.0.1 // @author X.I.U // @description 屏蔽指定域名、修复图标加载、链接不携来源、快捷回到顶部(右键两侧空白处) // @description:zh-CN 简单有效的全网通用护眼模式(夜间模式、暗黑模式、深色模式) // @description:zh-TW 屏蔽指定域名、修復圖標加載、鏈接不攜來源、快捷回到頂部(右鍵兩側空白處) // @description:en Block the specified domain name, fix icon loading, link without source, and quickly return to the top (the blank space on both sides of the right button)... // @match https://duckduckgo.com/* // @icon https://duckduckgo.com/favicon.ico // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // @grant GM_openInTab // @grant GM_getValue // @grant GM_setValue // @grant GM_notification // @license GPL-3.0 License // @run-at document-end // @namespace https://github.com/XIU2/UserScript // @supportURL https://github.com/XIU2/UserScript // @homepageURL https://github.com/XIU2/UserScript // @downloadURL none // ==/UserScript== (function() { 'use strict'; var menu_ALL = [ ['menu_blockDomainBtn', '显示屏蔽按钮', '显示屏蔽按钮', true], ['menu_blockDomain', '编辑屏蔽域名', '编辑屏蔽域名', []], ['menu_backToTop', '快捷回到顶部', '快捷回到顶部', true] ], menu_ID = []; for (let i=0;i menu_ALL.length){for (let i=0;i { for (const mutation of mutationsList) { for (const target of mutation.addedNodes) { if (target.nodeType != 1) break // 屏蔽指定域名 if (target.dataset.domain && checkDomain(target.dataset.domain)) {target.remove(); break;} // 修复图标加载 let img = target.querySelector('img.result__icon__img[data-src]'); // 寻找图标元素 if (img && !img.src) img.src = img.dataset.src // 链接不携来源 addRel(target); // 添加屏蔽按钮 addBlockDomainBtn(target, target.dataset.domain); } } }; const observer = new MutationObserver(callback); observer.observe(document, { childList: true, subtree: true }); } // 检查域名是否存在黑名单中 function checkDomain(domain) { let blockDomain = GM_getValue('menu_blockDomain'); for (let i=0; i屏蔽`); doc.querySelector('button.blockDomainBtn').addEventListener('click', function(e) { e.stopPropagation(); // 追加屏蔽域名 let blockDomain = GM_getValue('menu_blockDomain'); blockDomain.push(e.target.dataset.domain) GM_setValue('menu_blockDomain', blockDomain); // 隐藏该域名的所有搜索结果 document.querySelectorAll(`#links > div[data-domain="${e.target.dataset.domain}"]`).forEach(function(one){one.style.display = 'none'}) }); } } // 快捷回到顶部(右键两侧空白处) function backToTop() { if (!GM_getValue('menu_backToTop')) return document.querySelectorAll('#web_content_wrapper, #web_content_wrapper > .cw, #links_wrapper').forEach(ele => { ele.oncontextmenu = function(e) { if (e.target == this) { e.preventDefault(); window.scrollTo(0,0); } } }) } })();