Removing inflammatory YouTube comments programmatically

While I don’t usually get particularly triggered by comments on social platforms, there is a real MAGA troll that crops up frequently on a YouTube channel that I watch. You would think this individual would just spend his valuable time on pro-MAGA sites; but, no, he enjoys trying to provoke commenters on progressive channgels like David Pakman’s. Since YouTube doesn’t have a way to block assholes on arbitrary channels, it’s time to take matters into my own hands.

This is the kind of unhelpful, inflammatory comment that I’m trying to block:

Here’s how I do it.

Violentmonkey

Our blocker runs as a userscript in Violentmonkey, which is a free, open-source userscript manager available for Chromium-based browsers and Firefox. It allows users to run small JavaScript programs, called userscripts, that modify the behavior or appearance of websites. These scripts can automate tasks, remove ads, add features, or change layouts on web pages. Violentmonkey is compatible with most scripts written for Greasemonkey and Tampermonkey.

There are similar extensions including a port that runs on Safari, but this is what I use; and I use it in Firefox.

The script

Since the user ID of the person we’re trying to block is this: @_ID_as_Non_Bidenary we will of course need to define let asshole = '@_ID_as_Non_Bidenary'; Using the Firefox developer tools, we can find the largest block that encloses this user’s comments.

// ==UserScript==
// @name        Remove Specific YouTube Comments by ID
// @namespace   Violentmonkey Scripts
// @match       https://www.youtube.com/*
// @grant       none
// @version     1.0
// @author      Ojisan Seiuchi - 2025-06-11
// @description Removes YouTube comment blocks where the author's ID (from aria-label)
//              matches a specific pattern.
// ==/UserScript==

(function() {
    'use strict';

    /**
     * Finds and removes YouTube comment blocks based on the author's aria-label.
     * It specifically targets comments where the 'aria-label' attribute of the
     * author's thumbnail button starts with '@_ID_as_Non_Bidenary'.
     */
    function removeSpecificComments() {
        // Select all elements that represent a comment block.
        const commentViewModels = document.querySelectorAll('ytd-comment-view-model');

        commentViewModels.forEach(comment => {
            const authorThumbnailButton =
                comment.querySelector('button#author-thumbnail-button');

            if (authorThumbnailButton && authorThumbnailButton.ariaLabel) {
                if (authorThumbnailButton.ariaLabel.startsWith('@_ID_as_Non_Bidenary')) {
                    if (comment.parentNode) {
                        comment.parentNode.removeChild(comment);
                        console.log(
                            'Removed a comment block by:',
                            authorThumbnailButton.ariaLabel
                        );
                    }
                }
            }
        });
    }

    // --- Initial Run and Dynamic Content Handling ---

    // 1. Run once on script load
    removeSpecificComments();

    // 2. Observe DOM for dynamically loaded comments
    const observer = new MutationObserver((mutationsList, observer) => {
        for (const mutation of mutationsList) {
            if (
                mutation.type === 'childList' &&
                mutation.addedNodes.length > 0
            ) {
                removeSpecificComments();
            }
        }
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

})();

Next steps

  • Since there is more than one MAGA asshole, we should extend the script to allows us to filter an entire list of them.
  • Because there are still comments that mention the asshole, if we’re being really thorough, we should remove those as well.