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

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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 });
})();