Skip to content

Instantly share code, notes, and snippets.

@attitude
Last active May 29, 2016 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save attitude/5ae854e7cd425cd6e672c6910b859d2c to your computer and use it in GitHub Desktop.
Save attitude/5ae854e7cd425cd6e672c6910b859d2c to your computer and use it in GitHub Desktop.
Script to dim some SERP in Chrome; requires Control Freak extension.
(function(domains) {
var to,
observer,
// Google SERP div#search
search,
// Array of links
links,
// Passed arg iterator
domainsI,
// Passed arg length
domainsL = domains.length,
// Function to look for matching links
lookForAnchorElements = function() {
// Lookup links
links = search.getElementsByTagName('a');
if (links.length > 0) {
var i, l = links.length;
// Loop through passed domains
for (domainsI = 0; domainsI < domainsL; domainsI = domainsI + 1) {
// Loop through links
for (i = 0; i < l; i = i + 1) {
// Link has matching href attr
if (links[i].href && links[i].href.match('/' + domains[domainsI] + '/')) {
if (links[i].parentElement.parentElement.className.match(/^rc$/) && !links[i].parentElement.parentElement.$$hiddenSerp) {
// Mark element for easier skipping
links[i].parentElement.parentElement.$$hiddenSerp = true;
// Set opacity
links[i].parentElement.parentElement.style.opacity = 0.25;
}
}
}
}
}
},
// Function to look for the div#search element
lookForSearchElement = function() {
search = document.getElementById('search');
// If already found...
if (search) {
// ...clear timeout hack from below
clearInterval(to);
// Start links lookup
to = setTimeout(lookForAnchorElements, 300);
// Set-up observer
observer = new MutationObserver(function() {
// Clear previous link lookup
clearTimeout(to);
// Set new lookup
to = setTimeout(lookForAnchorElements, 300);
}).observe(
// Observed element
search,
// Observiing options
{childList: true, subtree: true, attributes: true}
);
}
};
// Loop until div#search element appears in DOM
to = window.setInterval(lookForSearchElement, 300);
}(['www.anyannoyingdomain.com'])); // Array of regexes of annoying domains you want to dimm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment