« get me outta code hell

No-reply-hider - remove1NonST - 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:27:59 -0300
committerFlorrie <towerofnix@gmail.com>2018-08-08 18:27:59 -0300
commite5a23c8b52e6fe4f9b15378fa0d6af45ee23489d (patch)
tree06fa0c6e46620bb2969d15635501b0f7c192b396
parent28e79c4afeb7255f74de06a058789cde31f0be66 (diff)
No-reply-hider - remove1NonST
-rw-r--r--README.md10
-rw-r--r--scratch-forums-no-reply-hider.js19
2 files changed, 23 insertions, 6 deletions
diff --git a/README.md b/README.md
index 6742e44..7ecb281 100644
--- a/README.md
+++ b/README.md
@@ -34,9 +34,13 @@ easier. I was looking for topics replied to by the ST, and this script follows
 the logical rule that if a topic has not been replied to by anybody, it has not
 been 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.
+By default, 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.
+
+You can also turn off the setting where posts with one reply not by the ST are
+hidden. (That follows the logical rule that if there was one reply, and the
+reply was not made by an ST member, there have been no replies by the ST.)
 
 ## scratch-colorful-messages (.css)
 
diff --git a/scratch-forums-no-reply-hider.js b/scratch-forums-no-reply-hider.js
index 0b02b2e..1a6f844 100644
--- a/scratch-forums-no-reply-hider.js
+++ b/scratch-forums-no-reply-hider.js
@@ -1,12 +1,24 @@
 // ==UserScript==
-// @name Hide Unreplied Posts
+// @name Hide Unreplied Topics
 // @namespace Violentmonkey Scripts
 // @match https://scratch.mit.edu/discuss/57/*
 // @grant none
 // ==/UserScript==
 
+// Customization ///////////////////////////////////////
+
+// Should topics which only have one reply be hidden
+// if that reply was not written by an ST member?
+const remove1NonST = true
+
+// Topic hiding ////////////////////////////////////////
+
+const stMembers = 'ceebee designerd kittyloaf shruti Champ99 dietbacon chrisg codubee sgcc_ dsquare scmb1 tarmelop quacht mres ericr natalie raimondious speakvisually thisandagain pandatt brycedtea Morant cwillisf pondermake stymphalianbirb'.split(' ')
+
 let numRemoved = 0, span
 
+const last = arr => arr[arr.length - 1]
+
 const observer = new MutationObserver(mutations => {
   let dirty = false
   for (const mutation of mutations) {
@@ -17,7 +29,8 @@ const observer = new MutationObserver(mutations => {
 
       if (node.matches('.box-content tr')) {
         const replyCount = parseInt(node.querySelector('.tc2').textContent)
-        if (replyCount === 0) {
+        const latestReplier = last(node.querySelector('.tcr').textContent.trim().split(' '))
+        if (replyCount === 0 || remove1NonST && replyCount === 1 && !stMembers.includes(latestReplier)) {
           node.remove()
           numRemoved++
           dirty = true
@@ -36,7 +49,7 @@ const observer = new MutationObserver(mutations => {
     while (span.firstChild) {
       span.removeChild(span.firstChild)
     }
-    span.appendChild(document.createTextNode(` - ${numRemoved} post${numRemoved === 1 ? '' : 's'} with no replies hidden`))
+    span.appendChild(document.createTextNode(` - ${numRemoved} topic${numRemoved === 1 ? '' : 's'} with no replies hidden`))
   }
 })