YouTube Channel Blocker by URL

Blocks videos by YouTube channel URL

Mint 2025.04.26.. Lásd a legutóbbi verzió

// ==UserScript==
// @name         YouTube Channel Blocker by URL
// @description  Blocks videos by YouTube channel URL
// @match        https://www.youtube.com/*
// @run-at       document-start
// @version 0.0.1.20250426082428
// @namespace https://greasyfork.org/users/1435046
// ==/UserScript==

(function() {
    'use strict';

    // List full channel URLs here (must include "/@handle")
    const blockedChannelUrls = [
        'https://www.youtube.com/@ThomasDeLauerOfficial',
        // add more URLs as needed
    ];

    // Extract lowercase handles from URLs
    const blockedHandles = blockedChannelUrls
        .map(url => {
            const m = url.match(/\/@([^\/?#]+)/);
            return m ? m[1].toLowerCase() : null;
        })
        .filter(Boolean);

    function blockVideos() {
        document.querySelectorAll('ytd-rich-item-renderer, ytd-video-renderer').forEach(el => {
            // look for any link to an @handle
            const link = el.querySelector('a[href*="/@"]');
            if (!link) return;
            const handle = link.href.split('/@')[1].split(/[\/?#]/)[0].toLowerCase();
            if (blockedHandles.includes(handle)) {
                el.remove();
            }
        });
    }

    // observe page changes (including SPA navigation)
    const observer = new MutationObserver(blockVideos);
    observer.observe(document, { childList: true, subtree: true });

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