xNhau Ad Blocker

Remove all ads and popups from xNhau

As of 08.05.2025. See ბოლო ვერსია.

// ==UserScript==
// @name         xNhau Ad Blocker
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Remove all ads and popups from xNhau
// @author       You
// @match        https://xnhau.im/*
// @match        https://*.xnhau.im/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    
    // Create a stylesheet to override ad-related styles
    const style = document.createElement('style');
    style.textContent = `
        .spot, .ad-container, [class*="banner"], [id*="banner"],
        [class*="catfish"], [id*="catfish"], [class*="popup"], [id*="popup"],
        [class*="ad-"], [id*="ad-"], [class*="ad_"], [id*="ad_"],
        iframe[src*="banner"], iframe[src*="ad"], 
        a[href*="utm_campaign"], a[href*="utm_medium"], a[target="_blank"][rel="nofollow"],
        div[style*="728px"][style*="90px"] { 
            display: none !important; 
            height: 0 !important; 
            width: 0 !important; 
            opacity: 0 !important; 
            pointer-events: none !important;
            position: absolute !important;
            visibility: hidden !important;
        }
    `;
    document.head.appendChild(style);
    
    // Block obfuscated ad scripts that create popunders
    const originalAppendChild = Element.prototype.appendChild;
    Element.prototype.appendChild = function(node) {
        if (node.tagName === 'SCRIPT') {
            const scriptContent = node.textContent || '';
            if (scriptContent.includes('_0x') || 
                scriptContent.includes('catfish') || 
                scriptContent.includes('popunder') || 
                scriptContent.includes('utm_')) {
                return document.createComment('Blocked ad script');
            }
        }
        return originalAppendChild.call(this, node);
    };
    
    // Block the open window function used by popunders
    window.open = function(url, name, specs) {
        if (url && (
            url.includes('utm_campaign') || 
            url.includes('utm_medium') || 
            url.includes('utm_source') ||
            url.includes('kbet.com') ||
            url.includes('lu88.com') ||
            url.includes('hit.club') ||
            url.includes('b52.cc')
        )) {
            console.log('Blocked popup:', url);
            return null;
        }
        return window.originalOpen.apply(this, arguments);
    };
    window.originalOpen = window.open;
    
    // Function to remove ads when DOM is loaded
    function removeAds() {
        // Remove specific ad containers
        const adSelectors = [
            '.spot', '.ad-container', '#catfishPcGuest', 
            'div[style*="728px"][style*="90px"]',
            'a[target="_blank"][rel="nofollow"]',
            'div.center-ad', 'video.center-ad'
        ];
        
        adSelectors.forEach(selector => {
            document.querySelectorAll(selector).forEach(el => {
                el.remove();
            });
        });
        
        // Remove all video ads
        document.querySelectorAll('video').forEach(video => {
            const parent = video.parentElement;
            if (parent && parent.tagName === 'A' && 
                (parent.href.includes('utm_') || parent.rel === 'nofollow')) {
                parent.remove();
            }
        });
        
        // Remove the obfuscated script container
        document.querySelectorAll('script').forEach(script => {
            const content = script.textContent || '';
            if (content.includes('_0x') || 
                content.includes('clickCount') || 
                content.includes('firstClickTime')) {
                if (script.parentNode) {
                    script.parentNode.removeChild(script);
                }
            }
        });
        
        // Clean localStorage to prevent ad tracking
        try {
            localStorage.removeItem('firstClickTime');
            localStorage.removeItem('clickCount');
        } catch (e) {}
    }
    
    // Run immediately and after DOM is fully loaded
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', removeAds);
    } else {
        removeAds();
    }
    
    // Set up a mutation observer to clean dynamically added ads
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            if (mutation.addedNodes && mutation.addedNodes.length > 0) {
                mutation.addedNodes.forEach(node => {
                    if (node.nodeType === 1) { // Element node
                        // Check if it's an ad
                        if (node.classList && 
                            (node.classList.contains('spot') || 
                             node.classList.contains('ad-container') ||
                             node.id === 'catfishPcGuest')) {
                            node.remove();
                        }
                        
                        // Check for video ads inside this node
                        if (node.querySelectorAll) {
                            removeAds();
                        }
                    }
                });
            }
        });
    });
    
    // Start observing the body for dynamically added content
    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });
    
    // Override the closeAd function to do nothing
    window.closeAd = function() { return false; };
    
    console.log('xNhau Ad Blocker: Active');
})();