One-click to remove a verbose site from Google Search results.

Adds a link to Google Search, to re-run the search with a domain removed. Preset for en.wikipedia.org, but this can easily be changed.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         One-click to remove a verbose site from Google Search results.
// @version      1.0
// @description  Adds a link to Google Search, to re-run the search with a domain removed. Preset for en.wikipedia.org, but this can easily be changed.
// @author       dhaden, based on a GitHub script by Ryan Buening, who based it on a Reddit blocking script.
// @include      http*://www.google.*/search*
// @include      http*://google.*/search*
// @run-at       document-end
// @namespace https://greasyfork.org/users/186630
// ==/UserScript==

// Change this to false if you do not want to add the link just to the right of Google's 'Tools' label.
const appendRight = true;

// There are two user USER VARIABLEs you can change below. The site URL and the text label.

// Set up the regex
const queryRegex = /q=[^&]+/g;
const siteRegex = /\+site(?:%3A|\:).+\.[^&+]+/g;
// ** USER VARIABLE - Change the URL after www. to the one you regularly want to remove from results.
// e.g. www.ncbi.nlm.nih.gov - remember to include the www. or equivalant, but not the http:// bit!
// The %3A bit means : in Google-speak.
const url = "+-site%3Aen.wikipedia.org";

(function() {
    // Creating the element
    var el = document.createElement('div');
    el.className = 'hdtb-mitem';
    var link = document.createElement('a');

    // Hyperlink and label, to add the knockout '-site:en.wikipedia.org' to the query.
    // ** USER VARIABLE - Change 'Remove' to change the wording of the new link label that appears on Google Search.
    link.appendChild(document.createTextNode('Remove'));
    link.href = window.location.href.replace(queryRegex, (match) => {
        // Replaces the existing 'site' flags
        return match.search(siteRegex) >= 0 ? match.replace(siteRegex, url) : match + url;
    });
    el.appendChild(link);

    // Inserting the element into Google search
    if (appendRight) {
        var toolsBtn = document.getElementById('hdtb-tls');
        toolsBtn.parentNode.insertBefore(el, toolsBtn.nextSibling);
    } else {
        var button = document.getElementById('hdtb-msb-vis');
        button.appendChild(el);
    }
})();