Lightweight YouTube AdBlock

Blocks ads on YouTube without eating up your resources

安装此脚本
作者推荐脚本

您可能也喜欢Hide youtube theather mode button

安装此脚本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Lightweight YouTube AdBlock
// @version      1.12
// @description  Blocks ads on YouTube without eating up your resources
// @author       equmaq
// @match        https://www.youtube.com/*
// @license      CC BY
// @namespace https://greasyfork.org/users/990886
// ==/UserScript==


(function() {
    'use strict';

    // Function to remove video ads
    function removeAds() {
        const adSelectors = [
            '.video-ads',
            '.ytp-ad-module',
            '.ytp-ad-overlay-slot',
            '.ytp-ad-overlay-close-button',
            '.ytp-ad-player-overlay',
            '.ytp-ad-player-overlay-instream-info',
            '.ytp-ad-player-overlay-instream-info-renderer',
            '.ytp-ad-player-overlay-instream-info-renderer-title',
            '.ytp-ad-player-overlay-instream-info-renderer-actions'
        ];

        adSelectors.forEach(selector => {
            const ads = document.querySelectorAll(selector);
            ads.forEach(ad => {
                ad.style.display = 'none';
            });
        });
    }

    // Wait for the page to load and remove ads
    window.addEventListener('load', removeAds);
    // Also, listen for AJAX navigation changes and remove ads accordingly
    window.addEventListener('yt-navigate-finish', removeAds);
})();