Last active
August 29, 2015 14:12
-
-
Save kroltan/3786844135f996bdff36 to your computer and use it in GitHub Desktop.
Userscript to ignore hot network questions on Stack Exchange sites(tested in Greasemonkey)
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 Stack Exchange Hot Network Questions Filter | |
// @namespace kroltan.stackexchange.hotfilter | |
// @description Allows hiding seen or uninteresting questions from the Hot Network Questions list. | |
// @include /^https?://.*\.stackoverflow\.com/.*/ | |
// @include /^https?://.*\.stackexchange\.com/.*/ | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
/* | |
* USAGE: | |
* To hide a question from the Hot Network Questions list, simply click its site's icon. | |
* Ignore lists are per-site, since it uses localStorage. | |
* Resetting the ignore list is a bit more involved, open the developer console and run: | |
* khotnet.reset() | |
*/ | |
$(document).ready(function() { | |
var withConfig = function(func) { | |
var key = "__krolstack_hotfilter"; | |
var config = { | |
"ignore":[] | |
}; | |
var data; | |
if ((data = localStorage.getItem(key)) !== null) { | |
config = JSON.parse(data); | |
} | |
var result = func(config); | |
localStorage.setItem(key, JSON.stringify(config)); | |
return result; | |
} | |
var isIgnored = function(id, config) { | |
var inner = function(config) { | |
return config.ignore.indexOf(id) > 0; | |
}; | |
return config? inner(config) : withConfig(inner); | |
} | |
var addIgnore = function(id) { | |
withConfig(function(config) { | |
if (!isIgnored(id, config)) { | |
config.ignore.push(id); | |
} | |
}); | |
}; | |
var reset = function() { | |
withConfig(function(config){ | |
var ignored = config.ignore; | |
while (ignored.length > 0) { | |
ignored.pop(); | |
} | |
}); | |
} | |
$("<style>" + | |
"#hot-network-questions ul li .favicon:hover {" + | |
" background-color: red;" + | |
" cursor: pointer;" + | |
"}" + | |
"</style>").appendTo("head"); | |
var hotNetList = $("#hot-network-questions ul"); | |
hotNetList.children("li").each(function(i) { | |
var self = $(this); | |
var icon = self.children(".favicon"); | |
var link = self.children("a"); | |
var linkParts = link.attr("href").split("/"); | |
var questionID = parseInt(linkParts[linkParts.length - 2], 10); | |
if (isIgnored(questionID)) { | |
self.remove(); | |
} | |
icon.click(function(evt) { | |
addIgnore(questionID); | |
self.remove(); | |
}); | |
}); | |
window.khotnet = { | |
addIgnore: addIgnore, | |
isIgnored: isIgnored, | |
reset: reset | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment