From 9fba1dea938db7aa4cc07f6d8e12d6d2c043c0c8 Mon Sep 17 00:00:00 2001 From: Florrie Date: Tue, 19 Jun 2018 20:35:46 -0300 Subject: Initial commit --- scratch-comment-blocker.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 scratch-comment-blocker.js (limited to 'scratch-comment-blocker.js') diff --git a/scratch-comment-blocker.js b/scratch-comment-blocker.js new file mode 100644 index 0000000..3e3823d --- /dev/null +++ b/scratch-comment-blocker.js @@ -0,0 +1,55 @@ +// ==UserScript== +// @name Scratch Comment Blocker +// @namespace Violentmonkey Scripts +// @match *://scratch.mit.edu/* +// @grant none +// ==/UserScript== + +// Customization /////////////////////////////////////// + +// Should comments written by any blocked users be +// hidden? +const blockComments = true + +// Should whole threads which ever had any posts by any +// blocked users be hidden? +const blockWholeThreads = true + +// Blocked users /////////////////////////////////////// + +// Just fill in the usernames of the users you choose +// to block here. +const blockedUsers = [] + +// Comment blocking //////////////////////////////////// + +if (blockComments) { + const commentsContainer = document.querySelector('#comments ul.comments') + + if (commentsContainer) { + const observer = new MutationObserver(mutations => { + for (const mutation of mutations) { + for (const addedNode of mutation.addedNodes) { + if (typeof addedNode.classList === 'undefined') continue + if (addedNode.classList.contains('top-level-reply') === false) continue + const topComment = addedNode + const comments = [topComment, ...topComment.getElementsByClassName('reply')] + + for (const comment of comments) { + const nameEl = comment.querySelector('.name a') + if (nameEl && blockedUsers.includes(nameEl.textContent)) { + if (blockWholeThreads) { + topComment.remove() + break + } else { + comment.remove() + } + } + } + } + } + }) + + observer.observe(commentsContainer, {childList: true}) + } +} -- cgit 1.3.0-6-gf8a5