Zanlix Auto Claim at 2/20 & Popup Block

Auto-claim ATTACK only at 2/20, refresh until target, block popups silently

// ==UserScript==
// @name         Zanlix Auto Claim at 2/20 & Popup Block
// @namespace    http://tampermonkey.net/
// @version      1
// @description  Auto-claim ATTACK only at 2/20, refresh until target, block popups silently
// @author       👽
// @match        https://zanlix.eu/game*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    // Random delay between 5 and 15 seconds
    function getRandomDelay() {
        return Math.floor(Math.random() * (15 - 5 + 1) + 5) * 1000;
    }

    function clickAttack() {
        const btn = document.querySelector('button[name="attack"]');
        if (btn && !btn.disabled) {
            btn.click(); // click only if enabled
        }
    }

    function checkAndClaim() {
        const counterSpan = document.querySelector('span.text-blue-400');
        if (!counterSpan) return;

        const text = counterSpan.textContent.trim();
        if (text === '2 / 20') {
            // At 2/20 energy, click attack after random delay
            setTimeout(clickAttack, getRandomDelay());
        }
    }

    function blockPopups() {
        // Block all new windows
        window.open = function () { return null; };

        // Remove any iframes (ads) every second
        setInterval(() => {
            document.querySelectorAll('iframe').forEach(f => f.remove());
        }, 1000);

        // Prevent links from opening in new tabs
        document.addEventListener('click', function (e) {
            const target = e.target.closest('a[target="_blank"]');
            if (target) e.preventDefault();
        }, true);
    }

    window.addEventListener('load', function () {
        blockPopups();

        // Check counter and click if matches
        checkAndClaim();

        // Refresh every 1 minute until counter reaches 2/20
        setInterval(() => {
            const counterSpan = document.querySelector('span.text-blue-400');
            if (counterSpan) {
                const text = counterSpan.textContent.trim();
                if (text !== '2 / 20') {
                    location.reload();
                } else {
                    // Already at target, do not refresh, just click
                    setTimeout(clickAttack, getRandomDelay());
                }
            } else {
                location.reload(); // fallback if counter not found
            }
        }, 60000);
    });
})();