Last active
July 20, 2026 17:43
-
-
Save NSBum/02b467d936a6973d0f45a20c8df0ea01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Political Wire - Hide Comments by Troll | |
| // @namespace https://politicalwire.com/ | |
| // @version 1.1 | |
| // @description Removes Disqus comments posted by specified trolls | |
| // @match https://politicalwire.com/* | |
| // @match https://*.disqus.com/embed/comments/* | |
| // @grant none | |
| // @run-at document-start | |
| // ==/UserScript== | |
| (function () { | |
| 'use strict'; | |
| const blockedTrolls = new Set([ | |
| 'Reasonable' | |
| ]); | |
| function removeBlockedComments(root = document) { | |
| const trollLinks = root.querySelectorAll( | |
| '.post-byline .author a[data-action="profile"]' | |
| ); | |
| for (const trollLink of trollLinks) { | |
| const trollName = trollLink.textContent.trim(); | |
| if (!blockedTrolls.has(trollName)) { | |
| continue; | |
| } | |
| /* | |
| * A Disqus comment is normally contained in an <li class="post">. | |
| * The additional selectors provide fallbacks if Disqus changes | |
| * its surrounding markup. | |
| */ | |
| const comment = trollLink.closest( | |
| 'li.post, article.comment, div.comment, [data-role="post"]' | |
| ); | |
| if (comment) { | |
| comment.remove(); | |
| } | |
| } | |
| } | |
| function startObserver() { | |
| removeBlockedComments(); | |
| const observer = new MutationObserver((mutations) => { | |
| for (const mutation of mutations) { | |
| for (const node of mutation.addedNodes) { | |
| if (!(node instanceof Element)) { | |
| continue; | |
| } | |
| if ( | |
| node.matches('.post-byline .author a[data-action="profile"]') || | |
| node.querySelector( | |
| '.post-byline .author a[data-action="profile"]' | |
| ) | |
| ) { | |
| removeBlockedComments(node.parentElement || node); | |
| } | |
| } | |
| } | |
| }); | |
| observer.observe(document.documentElement, { | |
| childList: true, | |
| subtree: true | |
| }); | |
| } | |
| if (document.readyState === 'loading') { | |
| document.addEventListener('DOMContentLoaded', startObserver, { | |
| once: true | |
| }); | |
| } else { | |
| startObserver(); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment