« get me outta code hell

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:
-rw-r--r--README.md3
-rw-r--r--scratch-forums-no-reply-hider.js12
2 files changed, 13 insertions, 2 deletions
diff --git a/README.md b/README.md
index 7ecb281..243f247 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,9 @@ 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.)
 
+The program won't hide the topics you created yourself. You can set an option
+to make it do that.
+
 ## 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
index 1a6f844..268d6a3 100644
--- a/scratch-forums-no-reply-hider.js
+++ b/scratch-forums-no-reply-hider.js
@@ -11,15 +11,22 @@
 // if that reply was not written by an ST member?
 const remove1NonST = true
 
+// Should topics that you created ever be hidden?
+const hideOwnTopics = false
+
 // 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
+let numRemoved = 0, span, ownUsername
 
 const last = arr => arr[arr.length - 1]
 
 const observer = new MutationObserver(mutations => {
+  if (!ownUsername && window.Scratch && Scratch.INIT_DATA.LOGGED_IN_USER.model) {
+    ownUsername = Scratch.INIT_DATA.LOGGED_IN_USER.model.username
+  }
+
   let dirty = false
   for (const mutation of mutations) {
     for (const node of mutation.addedNodes) {
@@ -30,7 +37,8 @@ const observer = new MutationObserver(mutations => {
       if (node.matches('.box-content tr')) {
         const replyCount = parseInt(node.querySelector('.tc2').textContent)
         const latestReplier = last(node.querySelector('.tcr').textContent.trim().split(' '))
-        if (replyCount === 0 || remove1NonST && replyCount === 1 && !stMembers.includes(latestReplier)) {
+        const author = last(node.querySelector('.tcl').textContent.trim().split(' '))
+        if ((hideOwnTopics || author !== ownUsername) && (replyCount === 0 || remove1NonST && replyCount === 1 && !stMembers.includes(latestReplier))) {
           node.remove()
           numRemoved++
           dirty = true