YouTube Username Blocker (Link-Based, Universal)

Blocks videos by clean profile URLs across all page layouts

// ==UserScript==
// @name         YouTube Username Blocker (Link-Based, Universal)
// @description  Blocks videos by clean profile URLs across all page layouts
// @match        https://www.youtube.com/*
// @run-at       document-start
// @version 0.0.1.20250426083653
// @namespace https://greasyfork.org/users/1435046
// ==/UserScript==

(function() {
    'use strict';

    // 1) Paste only clean channel URLs here (no trimming or lowercasing needed)
    const blockedUserLinks = [
        'https://www.youtube.com/@MikeThurston',
        'https://www.youtube.com/@ThomasDeLauerOfficial',
        'https://www.youtube.com/@gregdoucette',
        'https://www.youtube.com/@RenaissancePeriodization',
        'https://www.youtube.com/@penguinz0',
'https://www.youtube.com/@JeffNippard',
    ];

    // 2) Extract just the username part and normalize to lowercase
    const blockedUsernames = blockedUserLinks
        .map(link => {
            const m = link.match(/\/@([^\/?]+)/i);
            return m ? m[1].toLowerCase() : null;
        })
        .filter(name => name);

    // 3) Given an <a> element, remove its nearest video container if blocked
    function removeIfBlocked(link) {
        const href = link.getAttribute('href');
        const match = href && href.match(/\/@([^\/?]+)/);
        if (! match) return;
        const username = match[1].toLowerCase();
        if (! blockedUsernames.includes(username)) return;

        // nearest enclosing video/item container (covers most YouTube layouts)
        const container = link.closest(
            'ytd-rich-item-renderer, ytd-grid-video-renderer, ' +
            'ytd-video-renderer, ytd-compact-video-renderer, ' +
            'ytd-horizontal-list-item-renderer'
        );
        if (container) container.remove();
    }

    // 4) Scan the page for any new "@username" links and apply blocking
    function blockByUsername() {
        document
            .querySelectorAll('a[href*="/@"]')
            .forEach(removeIfBlocked);
    }

    // 5) Observe the entire document for dynamically inserted links
    const observer = new MutationObserver(blockByUsername);
    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });

    // 6) Initial pass
    blockByUsername();
})();