Remove results from Google and Qwant

Remove results from user-chosen sites on Google and Qwant.

// ==UserScript==
// @name        Remove results from Google and Qwant
// @name:it     Rimuovi risultati da Google e Qwant
// @namespace   StephenP
// @version     1.0.1.1
// @description  Remove results from user-chosen sites on Google and Qwant.
// @description:it  Rimuove i risultati di siti a scelta da Google e Qwant.
// @author       StephenP
// @match       https://www.google.it/search
// @match       https://www.google.com/search
// @match       https://www.qwant.com/?q=*
// @grant       none
// @contributionURL https://buymeacoffee.com/stephenp_greasyfork
// @license     AGPL-3.0-or-later
// ==/UserScript==

/*
Remove results from Google and Qwant
Copyright (C) 2022 StephenP
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

//EDIT THE LIST BELOW AS YOU LIKE: YOU CAN USE BOTH domain.tld OR subdomain.domain.tld FORMAT.
//MODIFICA LA LISTA SOTTOSTANTE COME VUOI: PUOI USARE SIA IL FORMATO domain.tld CHE subdomain.domain.tld.
const list=["example.tld",
           "subdomain.anotherexample.tld"];
main();
function main(){
  if(document.location.href.includes("google")){
    let resLinks=document.querySelectorAll("cite");
    if(resLinks.length>0){
      for(let l of resLinks){
        let res=l;
        for(let site of list){
          if((l.firstChild.data.slice(l.firstChild.data.lastIndexOf("/")+1)===site)||(l.firstChild.data.slice(l.firstChild.data.indexOf(".")+1)===site)){
            console.log("Found a result from "+site);
            while(((res.tagName!=="DIV")||(res.className!=="g"))&&(res.tagName!=="BODY")){
              res=res.parentNode;
            }
            if(res.tagName!=="BODY"){
              res.parentNode.remove(res);
              console.log("Removed a result from "+site);
            }
            break;
          }
        }
      }
    }
  }
  else if(document.location.href.includes("qwant")){
    qwantRemoveResultsFrom(document.body);
    let resultsContainer=document.querySelector("section[data-testid=containerWeb]");
    const config = { attributes: false, childList: true, subtree: true };
    const callback = function(mutationsList, observer) {
        for(const mutation of mutationsList) {
          if(mutation.addedNodes.length>0){
            for(node of mutation.addedNodes){
              qwantRemoveResultsFrom(node);
            }
          }
        }
    };
    const observer = new MutationObserver(callback);
    observer.observe(resultsContainer, config);
  }
}

function qwantRemoveResultsFrom(el){
  let resLinks=el.querySelectorAll("div[data-testid=webResult]");
  if(resLinks.length>0){
    for(let res of resLinks){
      let s=res.getAttribute("domain");
      for(let site of list){
        if((s.split("/")[2]===site)||(s.substring(s.indexOf(".")+1).split("/")[0]===site)){
          console.log("Found a result from "+site);
          res.style.display="none";
          console.log("Removed a result from "+site);
          break;
        }
      }
    }
  }
}