diff options
author | Florrie <towerofnix@gmail.com> | 2018-08-08 18:08:46 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-08-08 18:08:46 -0300 |
commit | 135ebe8cbad8ae5e700762d8c68c1a8985af44b3 (patch) | |
tree | 2cbf640da9a69718f50054f76e4e9cac72c5820d | |
parent | a4036f238d855d88542eeeb57792f991892772f8 (diff) |
scratch-forums-no-reply-hider
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | scratch-forums-no-reply-hider.js | 46 |
2 files changed, 58 insertions, 0 deletions
diff --git a/README.md b/README.md index 9f1abcc..eabc24a 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,18 @@ scratchr2, so it won't have an affect on places like your messages page. As such, it's not designed to work with people who actively try to interact with you. +## scratch-forums-no-reply-hider + +Hides forum topics that have not gotten any replies. This was made so that +skimming every topic created in the new Scratch 3.0 Beta forums would be +easier. I was looking for topics replied to by the ST, and this script follows +the logical rule that if a topic was not replied to by anybody, it was not +replied to by the ST. + +There isn't any configuration to be done, but the program only works on forum +ID 57 by default. You'll want to change the @match at the start to whatever +subforum you want to use the script on. + ## scratch-colorful-messages (.css) Userstyle that makes the message screen colorful, coloring each message row by diff --git a/scratch-forums-no-reply-hider.js b/scratch-forums-no-reply-hider.js new file mode 100644 index 0000000..0b02b2e --- /dev/null +++ b/scratch-forums-no-reply-hider.js @@ -0,0 +1,46 @@ +// ==UserScript== +// @name Hide Unreplied Posts +// @namespace Violentmonkey Scripts +// @match https://scratch.mit.edu/discuss/57/* +// @grant none +// ==/UserScript== + +let numRemoved = 0, span + +const observer = new MutationObserver(mutations => { + let dirty = false + for (const mutation of mutations) { + for (const node of mutation.addedNodes) { + if (!node.matches) { + continue + } + + if (node.matches('.box-content tr')) { + const replyCount = parseInt(node.querySelector('.tc2').textContent) + if (replyCount === 0) { + node.remove() + numRemoved++ + dirty = true + } + } + + if (!span && node.matches('.box-head h4')) { + span = document.createElement('span') + span.style.color = 'red' + node.appendChild(span) + } + } + } + + if (span && dirty) { + while (span.firstChild) { + span.removeChild(span.firstChild) + } + span.appendChild(document.createTextNode(` - ${numRemoved} post${numRemoved === 1 ? '' : 's'} with no replies hidden`)) + } +}) + +observer.observe(document.documentElement, { + childList: true, + subtree: true +}) |