blob: 3e3823d6069fa737b6cfe61de953ca94b143e83a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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})
}
}
|