YouTube - Hide Recommended Popups

Removes experimental and featured recommendation sections from YouTube

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

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