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.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
    }
})();