Created
January 25, 2022 22:09
-
-
Save ovelny/4aa69dd7879c2bd7f44b692fe96bd5c1 to your computer and use it in GitHub Desktop.
Filter SEO spam websites in google searches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Google search filter | |
// @version 1.0.0 | |
// @description Filter / blacklist sites in Google search | |
// @author ovelny | |
// @match *://www.google.com/search?* | |
// @run-at document-start | |
// ==/UserScript== | |
blacklist = [ | |
"programiz", | |
"qastack", | |
"qa-stack", | |
"kite", | |
"w3schools", | |
"tutorialspoint", | |
"towardsdatascience", | |
"geeksforgeeks", | |
"betterprogramming", | |
"linuxhint", | |
"makeuseof", | |
"codegrepper", | |
"solveforums" | |
] | |
const filterSites = function(blacklist) { | |
const citeEls = document.getElementsByTagName("cite") | |
let elsToDelete = [] | |
for (const element of citeEls) { | |
for (const site of blacklist) { | |
const regex = new RegExp(`^http.\:\/\/.*${site}.*$`, "gi") | |
const cite = element.childNodes[0].nodeValue | |
const match = cite.match(regex) | |
if (match) { | |
elsToDelete.push(element.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode) | |
} | |
} | |
} | |
if (elsToDelete.length) { | |
elsToDelete = elsToDelete.reverse() // we revert the elements so we can first delete nested ones in results | |
for (const element of elsToDelete) { | |
element.remove() | |
} | |
} | |
} | |
const removeCommonQuestions = function() { | |
const spans = document.getElementsByTagName("span") | |
let commonQuestions = [] | |
for (const span of spans) { | |
if (span) { | |
if (span.textContent == "People also ask") { | |
commonQuestions.push(span) | |
} | |
} | |
} | |
if (commonQuestions.length) { | |
const commonQuestionsBlock = commonQuestions[0].parentNode.parentNode.parentNode.parentNode | |
commonQuestionsBlock.remove() | |
} | |
} | |
if (document.readyState !== "loading") { | |
removeCommonQuestions() | |
filterSites(blacklist) | |
} else { | |
document.addEventListener("DOMContentLoaded", function() { | |
removeCommonQuestions() | |
filterSites(blacklist) | |
}) | |
} |
Thank you SO MUCH for this.
I am so glad I'm not the only soul writhing in pain seeing how low quality websites make their way to the top of search results whenever you're trying to look up docs for anything programming-related. Crazy how your blacklist exactly matches the one I had in mind.
Works perfect too! Thanks again.
You're welcome, glad this is useful! ✨
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you SO MUCH for this.
I am so glad I'm not the only soul writhing in pain seeing how low quality websites make their way to the top of search results whenever you're trying to look up docs for anything programming-related. Crazy how your blacklist exactly matches the one I had in mind.
Works perfect too! Thanks again.