Created
August 15, 2021 03:01
-
-
Save larsks/0fa08659c0592cbe26db09f0b491e932 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Hide closed and/or downvoted questions | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Hide closed questions on Stack Exchange sites | |
// @author [email protected] | |
// @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