YouTube - Hide Recommended Popups

Removes experimental and featured recommendation sections from YouTube

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==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
    });
})();