diff options
author | Florrie <towerofnix@gmail.com> | 2018-08-08 18:08:46 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-08-08 18:08:46 -0300 |
commit | 135ebe8cbad8ae5e700762d8c68c1a8985af44b3 (patch) | |
tree | 2cbf640da9a69718f50054f76e4e9cac72c5820d /scratch-forums-no-reply-hider.js | |
parent | a4036f238d855d88542eeeb57792f991892772f8 (diff) |
scratch-forums-no-reply-hider
Diffstat (limited to 'scratch-forums-no-reply-hider.js')
-rw-r--r-- | scratch-forums-no-reply-hider.js | 46 |
1 files changed, 46 insertions, 0 deletions
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 +}) |