Skip to content

Instantly share code, notes, and snippets.

@kms70847
Last active April 30, 2018 17:55
Show Gist options
  • Save kms70847/d4e206d3bc8eb950c675 to your computer and use it in GitHub Desktop.
Save kms70847/d4e206d3bc8eb950c675 to your computer and use it in GitHub Desktop.
Filters links out of Stack Overflow's "Hot Network Questions" sidebar
// ==UserScript==
// @name Network Bar Filter
// @namespace about:blank
// @include http://stackoverflow.com/*
// @include https://stackoverflow.com/*
// @include *.stackexchange.com/*
// @version 3
// @grant none
// ==/UserScript==
//returns true if item is in seq.
//(is there a built-in way to do this? I can't be bothered to check)
function contains(seq, item){
for(var i = 0; i < seq.length; i+=1){
if (seq[i] == item){return true;}
}
return false;
}
//returns true if the link didn't originate from a blacklisted site.
function is_good(list_item){
var blacklist = [
"Science Fiction & Fantasy Stack Exchange",
"Movies & TV Stack Exchange"
];
var title = list_item.getElementsByClassName("favicon")[0].title;
return !contains(blacklist, title);
}
/*filters all links out of the network bar, where func(link) is false.*/
function filter_network_bar(func){
var bar = document.getElementById("hot-network-questions");
var ul = bar.getElementsByTagName("ul")[0];
console.log(ul.children.length);
for (var i = 0; i < ul.children.length; i+=1){
var li = ul.children[i];
//console.log(li.getElementsByClassName("favicon")[0].title);
if (!func(li)){
var text_element = li.getElementsByTagName("A")[0];
text_element.title = text_element.innerHTML.trim();
text_element.innerHTML = "[Hover for potential spoilers]";
}
}
}
filter_network_bar(is_good);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment