Violentmonkey script to block politicalwire.com troll "Reasonable"
The news site politicalwire.com is a well-regarded site that covers U.S. political news. Like other similar sites, it features a comment section; and like many comment sections on political sites, it attracts personality-disordered internet trolls. One such troll on politicalwire.com goes by the handle Reasonable. This commenter is a troll in every sense of the word, engaging users with deliberately provocative nonsense.
This user has been banned on multiple occasions and escapes both bans and blocks by repeatedly creating new Disqus accounts using the same name and avatar. Since it cannot be blocked at the account/server level, I’ve written a Violentmonkey script to expunge his comments at the level of the browser. To use the script, you will need to use the Violentmonkey (or related) extension and create a new script with the following code. It works perfectly in Firefox.
// ==UserScript==
// @name Political Wire - Hide Comments by Author
// @namespace https://politicalwire.com/
// @version 1.0
// @description Removes Disqus comments posted by specified authors
// @match https://politicalwire.com/*
// @match https://*.disqus.com/embed/comments/*
// @grant none
// @run-at document-start
// ==/UserScript==
(function () {
'use strict';
const blockedAuthors = new Set([
'Reasonable'
]);
function removeBlockedComments(root = document) {
const authorLinks = root.querySelectorAll(
'.post-byline .author a[data-action="profile"]'
);
for (const authorLink of authorLinks) {
const authorName = authorLink.textContent.trim();
if (!blockedAuthors.has(authorName)) {
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 = authorLink.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();
}
})();