Skip to content

Instantly share code, notes, and snippets.

@larsks
Created August 15, 2021 03:01
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 larsks/0fa08659c0592cbe26db09f0b491e932 to your computer and use it in GitHub Desktop.
Save larsks/0fa08659c0592cbe26db09f0b491e932 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Hide closed and/or downvoted questions
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Hide closed questions on Stack Exchange sites
// @author lars@oddbit.com
// @match *://serverfault.com/
// @match *://stackoverflow.com/
// @match *://superuser.com/
// @match *://*.stackexchange.com/
// @icon https://www.google.com/s2/favicons?domain=stackexchange.com
// @grant none
// ==/UserScript==
var hide_closed_questions = true;
var hide_downvoted_questions = true;
var hide_downvoted_below = 0;
(function() {
'use strict';
function hideNodes(nodes) {
var thisNode
for (let i=0; thisNode = nodes.snapshotItem(i); i++) {
fadeOutEffect(thisNode)
}
}
// https://stackoverflow.com/a/29017547/147356
function fadeOutEffect(fadeTarget) {
var fadeEffect = setInterval(function () {
if (!fadeTarget.style.opacity) {
fadeTarget.style.opacity = 1
}
if (fadeTarget.style.opacity > 0) {
fadeTarget.style.opacity -= 0.1
} else {
fadeTarget.style.display = "none"
clearInterval(fadeEffect)
}
}, 200);
}
// hide all questions that contain "[closed]" in the question title
if (hide_closed_questions) {
var selected = document.evaluate (
'//div[contains(@class, "question-summary") and contains(.//a/text(), "[closed]")]',
document.documentElement,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null
);
hideNodes(selected)
}
// hide all questions with a score below hide_downvoted_below
if (hide_downvoted_questions) {
selected = document.evaluate (
`//div[contains(@class, "question-summary") and .//div[@class="votes"]//span[text() < ${hide_downvoted_below}]]`,
document.documentElement,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null
);
hideNodes(selected)
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment