« get me outta code hell

scratch-forums-no-reply-hider - scratch-userscripts - Handy userscripts for the Scratch website - issues/ideas: https://notabug.org/towerofnix/scratch-userscripts/issues
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-08-08 18:08:46 -0300
committerFlorrie <towerofnix@gmail.com>2018-08-08 18:08:46 -0300
commit135ebe8cbad8ae5e700762d8c68c1a8985af44b3 (patch)
tree2cbf640da9a69718f50054f76e4e9cac72c5820d
parenta4036f238d855d88542eeeb57792f991892772f8 (diff)
scratch-forums-no-reply-hider
-rw-r--r--README.md12
-rw-r--r--scratch-forums-no-reply-hider.js46
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
+})