YouTube: Block All Sponsored Videos on Home Page (Stable Layout)

Remove all YouTube ads and sponsored content. Keeps homepage layout stable and clean.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         YouTube: Block All Sponsored Videos on Home Page (Stable Layout)
// @namespace    https://greasyfork.org/en/users/1501169-mpatra193
// @version      1.5
// @description  Remove all YouTube ads and sponsored content. Keeps homepage layout stable and clean.
// @author       Monalisha Patra
// @match        *://www.youtube.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    let debounceTimeout;

    function removeAds() {
        // Remove player ads, overlays, banners
        document.querySelectorAll([
            '#player-ads',
            '.ytp-ad-module',
            '.ytp-ad-overlay-container',
            '.video-ads',
            '.ytp-ad-player-overlay',
            'ytd-display-ad-renderer',
            'ytd-promoted-sparkles-text-search-renderer',
            'ytd-promoted-video-renderer',
            '#masthead-ad'
        ].join(',')).forEach(el => el.remove());

        // Remove sponsored videos from feed/home
        const items = document.querySelectorAll('ytd-rich-item-renderer, ytd-video-renderer');
        for (const el of items) {
            const text = el.innerText.toLowerCase();
            if (/\bsponsored\b|\bad\b|\bpromotion\b/.test(text)) {
                el.remove();
            }
        }
    }

    function debounceRemoveAds() {
        clearTimeout(debounceTimeout);
        debounceTimeout = setTimeout(removeAds, 1200);
    }

    // Initial run
    window.addEventListener('load', () => {
        setTimeout(removeAds, 1800);
    });

    // Observe page changes but debounce DOM processing
    const observer = new MutationObserver(debounceRemoveAds);
    observer.observe(document.body, { childList: true, subtree: true });
})();