Advanced Adblocker

A comprehensive adblocker script for Tampermonkey

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Advanced Adblocker
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  A comprehensive adblocker script for Tampermonkey
// @author       You
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const userPreferences = JSON.parse(localStorage.getItem("adblockerPreferences")) || {
        blockPopups: true,
        blockNativeAds: true,
        blockIframeAds: true,
        blockScriptAds: true,
        blockSponsoredContent: true,
        blockAntiAdBlock: true
    };

    function hideAndRemove(element) {
        if (element) {
            element.style.display = "none";
            element.remove();
        }
    }

    function blockAds() {
        const adSelectors = [
            '.adsbygoogle',
            '.ad-container',
            '.banner-ad',
            '#ad',
            '[id^="ad_"]',
            '[class*="ad"]',
            '[src*="ads"]',
            '.sponsored',
            '.google-auto-placed',
            '.advertisement',
            '#advertisement',
            'div[data-ad]',
            '.popup-ad',
            '.native-ad',
            'iframe[src*="doubleclick"]',
            '.social-widget',
            '.ad-overlay',
            '[src*="ads"]',
            '[src*="doubleclick"]',
            '.google-ads',
            '#ad-banner'
        ];

        adSelectors.forEach(function(selector) {
            document.querySelectorAll(selector).forEach(hideAndRemove);
        });

        if (userPreferences.blockScriptAds) {
            document.querySelectorAll('script').forEach(function(script) {
                if (script.src && script.src.includes('ads')) {
                    hideAndRemove(script);
                } else if (script.innerHTML && script.innerHTML.includes('ads')) {
                    hideAndRemove(script);
                }
            });
        }

        if (userPreferences.blockPopups) {
            document.querySelectorAll('.popup-ad, .ad-overlay').forEach(hideAndRemove);
        }

        if (userPreferences.blockNativeAds) {
            document.querySelectorAll('.native-ad, .sponsored-post').forEach(hideAndRemove);
        }
    }

    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.type === 'childList') {
                blockAds();
            }
        });
    });

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

    function checkForAntiAdblock() {
        if (userPreferences.blockAntiAdBlock) {
            const antiAdblockBanner = document.querySelector('.anti-adblock-banner');
            if (antiAdblockBanner) {
                console.log("Anti-Adblock detected. Disabling adblock for this site.");
                blockAds();
            }
        }
    }

    setInterval(function() {
        blockAds();
        checkForAntiAdblock();
    }, 2000);

    blockAds();
    checkForAntiAdblock();

})();