// ==UserScript== // @name Google Block Website Results // @namespace http://tampermonkey.net/ // @version 0.1.1 // @description Adds the option to hide search results from the google search. A new block icon is visible next to the search result. When clicked you are promted to confirm the blocking of the domain. The amount of search results will not be adjusted, so if you block all websites on page 1, then page 1 will be empty. You can remove websites right now only by editing the script storage, // @author LostFelix // @license MIT // @match https://www.google.com/search* // @icon https://www.google.com/s2/favicons?sz=64&domain=google.com // @grant GM_setValue // @grant GM_getValue // @downloadURL none // ==/UserScript== (function() { 'use strict'; let domainsToBlock = []; init(); function init(){ domainsToBlock = GM_getValue('domainsToBlock',[]); nuke(); setInterval(nuke,1000); } function nuke(force = false){ let search = document.querySelector('#search'); if(!search){ return; } if(force){ search.querySelectorAll('.MjjYud .A6K0A .Ww4FFb a[jsname="UWckNb"][data-nuked]').forEach((el) => { delete el.dataset.nuked; }); } search.querySelectorAll('.MjjYud .A6K0A .Ww4FFb a[jsname="UWckNb"]:not([data-nuked])').forEach((el) => { if(el.classList.length > 0){ return; } domainsToBlock.forEach( (domain) => { if(el.href.includes(domain)){ let parent = getListElParentTop(el); parent.style.opacity = 0.5; parent.style.transform = "scale(0.75)"; parent.style.transformOrigin = "top left"; parent.style.height = parent.getBoundingClientRect().height +"px"; parent.style.display = "none"; } }); addBlockButton(el); el.dataset.nuked = "1"; }); } function addBlockButton(link){ const el = getListElParentTop(link).querySelector('.D6lY4c'); if(el.querySelector('.nuke-button')){ return; }; el.style.position = "relative"; let btn = document.createElement('button'); btn.innerHTML = ''; btn.classList.add('nuke-button'); btn.style.background = "transparent"; btn.style.border = 0; btn.style.cursor = "pointer"; btn.style.height = "100%"; btn.style.padding = 0; btn.style.margin = "0 3px"; btn.style.display = "inline-block"; btn.addEventListener('click',(e) => { e.stopPropagation(); e.preventDefault(); let href = link.href; let domain = href.replace(/^http.*\/\//,'').replace(/\/.*/,''); if(!domainsToBlock.includes(domain)){ if(window.confirm("Do you want to block: "+domain)){ domainsToBlock.push(domain); GM_setValue('domainsToBlock',domainsToBlock); nuke(true) } } }); el.appendChild(btn); console.log(el); } function getListElParentTop(el){ let parent = el.parentElement; let target = null while(parent){ if(parent.classList.contains('MjjYud')){ if(parent.parentElement.classList.contains('hlcw0c')){ target = parent.parentElement; }else{ target = parent; } parent = null; }else{ parent = parent.parentElement; } } return target; } })();