Skip to content

Instantly share code, notes, and snippets.

@kelunik
Created December 9, 2014 13:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kelunik/255a092c6fe5264c9def to your computer and use it in GitHub Desktop.
Save kelunik/255a092c6fe5264c9def to your computer and use it in GitHub Desktop.
Remove w3schools.com from Google Search results
// ==UserScript==
// @name Remove w3schools.com from Google
// @namespace https://www.kelunik.com
// @include https://www.google.com/*
// @include https://www.google.de/*
// @version 1
// @grant none
// ==/UserScript==
function forEach(list, callback) {
Array.prototype.forEach.call(list, callback);
}
var cleanupResults = function() {
forEach(document.getElementsByTagName('cite'), function(o) {
if(o.textContent.indexOf("w3schools.com") > 0) {
var node = o.parentNode.parentNode.parentNode.parentNode.parentNode;
node.parentNode.removeChild(node);
}
});
}; cleanupResults();
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
cleanupResults();
});
});
observer.observe(document.body, { childList: true });
@idontusenumbers
Copy link

idontusenumbers commented Nov 15, 2016

This wasn't working for me as is so I added a gross timeout:

var i = 0;
var cleanupResults = function() {
    if (i > 1000)
        return;
    
	forEach(document.getElementsByTagName('cite'), function(o) {
		if(o.textContent.indexOf("w3schools.com") > 0) {
			var node = o.parentNode.parentNode.parentNode.parentNode.parentNode;
			node.parentNode.removeChild(node);
		}
	});
    setTimeout(cleanupResults,15);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment