Smart Ad Blocker

Blocks ads while minimizing detection of adblocker

目前为 2024-08-28 提交的版本。查看 最新版本

// ==UserScript==
// @name         Smart Ad Blocker
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  Blocks ads while minimizing detection of adblocker
// @match        *://*/*  // Adjust this to match the sites where you want to run the script
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to handle ad elements
    function handleAds() {
        // List of common ad container selectors
        const adSelectors = [
            'iframe[src*="ads"]', // If the ad is in an iframe
            'iframe[src*="advertising"]',
            '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');
        });

        // 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(handleAds, 2000);

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

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

    // Initial handling
    handleAds();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址