Greasy Fork is available in English.

FreeLTC Auto Debug & Retry

clicks and refresh

// ==UserScript==
// @name         FreeLTC Auto Debug & Retry
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  clicks and refresh
// @author       👽
// @match        https://freeltc.fun/faucet/currency/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function waitForVerification() {
        const verificationDiv = document.querySelector('.iconcaptcha-modal__body-title');
        console.log("Checking verification div:", verificationDiv ? `"${verificationDiv.textContent.trim()}"` : "Not found");

        if (verificationDiv && verificationDiv.textContent.trim() === "Verification complete.") {
            console.log("✅ Verification complete detected. Waiting 2 seconds before clicking Claim...");
            setTimeout(clickClaim, 2000);
        } else {
            setTimeout(waitForVerification, 1000);
        }
    }

    function clickClaim() {
        const claimBtn = document.getElementById('subbutt');
        console.log("Claim button element:", claimBtn);

        if (claimBtn && !claimBtn.disabled) {
            console.log("👉 Clicking Claim Now button.");
            claimBtn.click();

            // Wait and try clicking OK button with retries
            setTimeout(() => retryClickOK(0), 3000); // start after 3 sec for better reliability
        } else {
            console.log("⚠️ Claim button not found or disabled. Retrying verification check...");
            // Restart the verification wait just in case
            waitForVerification();
        }
    }

    function retryClickOK(attempt) {
        const okBtn = document.querySelector('button.swal2-confirm.swal2-styled');
        console.log(`Attempt ${attempt + 1}: OK button element:`, okBtn);

        if (okBtn && okBtn.offsetParent !== null) {
            console.log("👉 Clicking OK button.");
            okBtn.click();

            setTimeout(() => {
                console.log("🔄 Refreshing the page now...");
                safeRefresh();
            }, 5000);

        } else if (attempt < 15) {
            console.log(`⌛ OK button not found or hidden. Retrying in 1 second (attempt ${attempt + 1})`);
            setTimeout(() => retryClickOK(attempt + 1), 1000);
        } else {
            console.log("⚠️ OK button not found after multiple attempts. Refreshing anyway.");
            safeRefresh();
        }
    }

    function safeRefresh() {
        // Try standard reload
        try {
            location.reload();
        } catch (e) {
            console.log("Error on location.reload(), trying href reset:", e);
            window.location.href = window.location.href;
        }
    }

    // Start process
    waitForVerification();

})();