YouTube - Hide Recommended Popups

Removes experimental and featured recommendation sections from YouTube

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         YouTube - Hide Recommended Popups
// @description  Removes experimental and featured recommendation sections from YouTube
// @namespace    http://tampermonkey.net/
// @icon         https://cdn-icons-png.flaticon.com/64/2504/2504965.png
// @version      0.0.5
// @author       rxm
// @match        https://www.youtube.com/*
// @license      MIT
// @grant        none
// ==/UserScript==

(() => {
    'use strict';

    const REMOVED_FLAG = 'data-yt-cleaned';

    function isUnwantedSection(el) {
        if (el.hasAttribute(REMOVED_FLAG)) return false;

        return (
            // Talk to Recs experiment
            el.querySelector('ytd-talk-to-recs-flow-renderer') ||

            // Experimental banners / promos
            el.querySelector('#big-yoodle') ||

            // Statement-style banners
            el.tagName === 'YTD-STATEMENT-BANNER-RENDERER'
        );
    }

    function removeIfUnwanted(el) {
        if (isUnwantedSection(el)) {
            el.setAttribute(REMOVED_FLAG, 'true');
            el.remove();
            console.debug('[YT Cleaner] Removed experimental recommendation section');
        }
    }

    function scan(node) {
        if (node.nodeType !== 1) return;

        if (
            node.matches?.(
                'ytd-rich-section-renderer, ytd-statement-banner-renderer'
            )
        ) {
            removeIfUnwanted(node);
        }

        node.querySelectorAll?.(
            'ytd-rich-section-renderer, ytd-statement-banner-renderer'
        ).forEach(removeIfUnwanted);
    }

    // Initial scan
    scan(document.body);

    // Observe only added nodes (much cheaper)
    const observer = new MutationObserver(mutations => {
        for (const m of mutations) {
            for (const node of m.addedNodes) {
                scan(node);
            }
        }
    });

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