diff --git a/DuckDuckGo-Enhanced.user.js b/DuckDuckGo-Enhanced.user.js new file mode 100644 index 0000000..6a243e2 --- /dev/null +++ b/DuckDuckGo-Enhanced.user.js @@ -0,0 +1,145 @@ +// ==UserScript== +// @name DuckDuckGo 增强 +// @version 1.0.0 +// @author X.I.U +// @description 屏蔽指定域名、修复图标加载、链接不携来源、快捷回到顶部(右键两侧空白处) +// @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 +// ==/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.getElementById('web_content_wrapper').oncontextmenu = document.getElementById('links_wrapper').oncontextmenu = function(e){ + if (e.target == this) { + e.preventDefault(); + window.scrollTo(0,0); + } + } + } +})(); \ No newline at end of file diff --git a/README.md b/README.md index 69febc4..0ffedf1 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ | [](https://bbs.3dmgame.com) | **3DM论坛 增强** | **自动回复**、自动无缝翻页、清理置顶帖子、自动滚至隐藏... | **[安装](https://greasyfork.org/zh-CN/scripts/412890)** \| **[备用](https://cdn.jsdelivr.net/gh/XIU2/UserScript/3dm-Enhanced.user.js)** | | [](https://www.lanzou.com) | **蓝奏云网盘 增强 \*** | **右键显示菜单**、直接下载文件、显示更多文件、自动密码... | **[安装](https://greasyfork.org/zh-CN/scripts/419224)** \| **[备用](https://cdn.jsdelivr.net/gh/XIU2/UserScript/Lanzou-Enhanced.user.js)** | | [](https://github.com/XIU2) | **新标签页打开链接 \*** | 将网页中所有链接改为新标签页打开~ | **[安装](https://greasyfork.org/zh-CN/scripts/429714)** \| **[备用](https://cdn.jsdelivr.net/gh/XIU2/UserScript/TargetBlank.user.js)** | +| [](https://store.steampowered.com) | **DuckDuckGo 增强** | **屏蔽指定域名**、修复图标加载、链接不携来源、快捷回到... | **[安装](https://greasyfork.org/zh-CN/scripts/436428)** \| **[备用](https://cdn.jsdelivr.net/gh/XIU2/UserScript/DuckDuckGo-Enhanced.user.js)** | | [](https://www.52pojie.cn) | **吾爱破解论坛 美化** | 精简多余内容、样式优化 | **[安装](https://greasyfork.org/zh-CN/scripts/412681)** \| **[备用](https://cdn.jsdelivr.net/gh/XIU2/UserScript/52pojie-Beautification.user.js)** | | [](https://www.52pojie.cn) | **吾爱破解论坛 增强** | **自动签到**、自动无缝翻页、屏蔽导读悬赏贴 (最新发表页)... | **[安装](https://greasyfork.org/zh-CN/scripts/412680)** \| **[备用](https://cdn.jsdelivr.net/gh/XIU2/UserScript/52pojie-Enhanced.user.js)** | | [](https://hostloc.com) | **全球主机交流论坛 增强 \*** | **自动访问空间(22积分)、屏蔽用户**、屏蔽关键词、自动翻... | **[安装](https://greasyfork.org/zh-CN/scripts/414005)** \| **[备用](https://cdn.jsdelivr.net/gh/XIU2/UserScript/Hostloc-Enhanced.user.js)** |