Universal Ad Blocker

Blocks ads on all sites

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Universal Ad Blocker
// @namespace    http://tampermonkey.net/
// @version      0.6
// @description  Blocks ads on all sites
// @match        *://*/*  // Apply to all URLs
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to handle ad elements
    function blockAds() {
        // List of common ad container selectors
        const adSelectors = [
            'iframe[src*="ads"]', 
            'iframe[src*="advertising"]',
            'iframe[src*="ad"]',
            'div[id*="ad"]',
            'div[class*="ad"]',
            'div[class*="banner"]',
            'div[id*="banner"]',
            'div[class*="promo"]',
            'div[id*="promo"]',
            'div[class*="sponsor"]',
            'div[id*="sponsor"]',
            'div[id*="google_ads"]',
            'div[id*="ad-container"]',
            'div[class*="ad-container"]',
            'a[href*="ad"]',
            'a[href*="advert"]',
            'script[src*="ads"]',
            'script[src*="advertising"]'
        ];

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

        // Remove ad elements
        adSelectors.forEach(selector => {
            const ads = document.querySelectorAll(selector);
            ads.forEach(ad => ad.remove());
        });

        // Close ad pop-ups
        const closeSelectors = ['.close-button', '.ad-close', '.dismiss-ad', '.close', '[aria-label="Close"]'];
        closeSelectors.forEach(selector => {
            const closeButtons = document.querySelectorAll(selector);
            closeButtons.forEach(button => button.click());
        });
    }

    // Check for ads every 2 seconds
    setInterval(blockAds, 2000);

    // Observe DOM changes to catch dynamically loaded ads
    const observer = new MutationObserver(mutations => {
        mutations.forEach(() => blockAds());
    });

    observer.observe(document.body, { childList: true, subtree: true });

    // Initial handling
    blockades();
})();