YouTube - Hide Recommended Popups

Removes experimental and featured recommendation sections from YouTube

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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
    });
})();