L-T

Wait for value

// ==UserScript==
// @name         L-T
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Wait for value
// @author       👽
// @match        https://ltc-trx-faucet.xyz/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    const TARGET_VALUE = 0.00001000;

    // 🔘 Simulate a real user click
    function simulateClick(element) {
        if (!element) return;
        ['mouseover', 'mousedown', 'mouseup', 'click'].forEach(type => {
            element.dispatchEvent(new MouseEvent(type, {
                view: window,
                bubbles: true,
                cancelable: true,
                buttons: 1
            }));
        });
    }

    // 🔍 Parse value string like "$0.00000062" into number
    function parseValue(str) {
        return parseFloat(str.replace(/[^0-9.]/g, ''));
    }

    // 🕓 Monitor value and claim when ready
    function monitorAndClaim() {
        const interval = setInterval(() => {
            const valueElem = document.querySelector('#st');
            const claimBtn = document.querySelector('#claim-reward');

            if (!valueElem || !claimBtn) {
                console.log('[AutoClaim] Waiting for #st or #claim-reward...');
                return;
            }

            const currentValue = parseValue(valueElem.textContent);
            console.log(`[AutoClaim] Current value: ${currentValue}`);

            if (currentValue >= TARGET_VALUE) {
                if (claimBtn.offsetParent !== null && !claimBtn.disabled) {
                    console.log('[AutoClaim] Target reached. Clicking claim...');
                    clearInterval(interval);
                    simulateClick(claimBtn);

                    // Step 3: Wait 2 seconds then click OK
                    setTimeout(() => {
                        const okBtn = document.querySelector('.swal2-confirm.swal2-styled');
                        if (okBtn && okBtn.offsetParent !== null) {
                            console.log('[AutoClaim] Clicking OK button...');
                            simulateClick(okBtn);
                        } else {
                            console.log('[AutoClaim] OK button not found or hidden.');
                        }
                    }, 2000);
                } else {
                    console.log('[AutoClaim] Claim button not ready.');
                }
            }
        }, 5000); // check every 5 seconds
    }

    // 🚀 Start the script
    window.addEventListener('load', () => {
        console.log('[AutoClaim] Script running...');
        monitorAndClaim();
    });

})();