From 135ebe8cbad8ae5e700762d8c68c1a8985af44b3 Mon Sep 17 00:00:00 2001 From: Florrie Date: Wed, 8 Aug 2018 18:08:46 -0300 Subject: scratch-forums-no-reply-hider --- scratch-forums-no-reply-hider.js | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 scratch-forums-no-reply-hider.js (limited to 'scratch-forums-no-reply-hider.js') 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 +}) -- cgit 1.3.0-6-gf8a5