Google Search Result Domain Blocker

This script blocks domains from your google search results.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Google Search Result Domain Blocker
// @namespace    mailto:[email protected]
// @version      0.1
// @description  This script blocks domains from your google search results.
// @author       [email protected]
// @match        https://www.google.com/search*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    //Load Filter
    let filter = {
        //'example.com' : true
    };

    //Cull Results
    let results = document.querySelectorAll('.rc');
    results.forEach((res)=>{
        //Get Domain
        let url = res.childNodes[0].childNodes[0].href;
        url = getDomain(url);

        if (filter[url]){
            res.parentNode.remove();
            console.log(`Filtered a result from: ${url}`);
        }
    });

    //Helper Functions
    function getDomain(url){
        url = url.slice( url.search('://')+3);
        url = url.slice(0, url.indexOf('/'));

        //Trim Subdomain
        if (url.split('.').length>2) {
            url = url.slice(url.indexOf('.')+1);
        }

        return url;
    }
})();