YouTube Username Blocker (Link-Based)

Blocks YouTube videos by clean profile URLs

Ekde 2025/04/26. Vidu La ĝisdata versio.

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

(function() {
    'use strict';

    // Add full clean user links here
    const blockedUserLinks = [
        'https://www.youtube.com/@MikeThurston',
'https://www.youtube.com/@ThomasDeLauerOfficial',
        // Add more clean channel URLs here
    ];

    // Preprocess: extract usernames from URLs
    const blockedUsernames = blockedUserLinks.map(link => {
        const match = link.match(/\/@([^/]+)/i);
        return match ? match[1].toLowerCase() : null;
    }).filter(name => name !== null);

    function blockVideos() {
        document.querySelectorAll('ytd-rich-item-renderer').forEach(video => {
            const channelLink = video.querySelector('a[href^="/@"]');
            if (channelLink) {
                const username = channelLink.href.split('/@')[1].split('/')[0].toLowerCase();
                if (blockedUsernames.includes(username)) {
                    video.remove();
                }
            }
        });
    }

    const observer = new MutationObserver(() => {
        blockVideos();
        document.querySelectorAll('ytd-rich-item-renderer').forEach(video => {
            if (video.shadowRoot) {
                video.shadowRoot.querySelectorAll('a[href^="/@"]').forEach(link => {
                    const username = link.href.split('/@')[1].split('/')[0].toLowerCase();
                    if (blockedUsernames.includes(username)) {
                        video.remove();
                    }
                });
            }
        });
    });

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

    document.addEventListener('yt-navigate-finish', blockVideos);
    blockVideos();
})();