Gamerlee auto faucet (not working)

Automatically Login and Click Faucet

// ==UserScript==
// @name         Gamerlee auto faucet (not working)
// @namespace    bekerja pada tampermonkey maupun violentmonkey
// @version      0.5
// @description  Automatically Login and Click Faucet
// @author       Ojo Ngono
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_addStyle
// @grant        GM_registerMenuCommand
// @require      https://update.greasyfork.org/scripts/439099/1203718/MonkeyConfig%20Modern%20Reloaded.js
// @match        https://gamerlee.com/*
// @license      Copyright OjoNgono
// @antifeature  referral-link Directs to a referral link when not logged in
// ==/UserScript==

const cfg = new MonkeyConfig({
    title: 'Input Email Faucetpay:',
    menuCommand: true,
    params: {
        Email: {
            label: "Email Faucetpay",
            type: "text",
            default: ''
        },
    }
});

(function() {
    'use strict';

    window.addEventListener('load', () => {
        const email = cfg.get('Email');
        if (!email || email.trim() === '') {
            enforceLogoutWithWarning();
        } else {
            enforceReferralUrl();
            setTimeout(() => {
                if (isLoggedIn()) {
                    fillEmailField(email);
                    rotateUrls();
                }
            }, 1000);
        }
    });

    function isLoggedIn() {
        const userDropdownButton = document.querySelector('#page-header-user-dropdown');
        return userDropdownButton !== null;
    }

    function enforceLogoutWithWarning() {
        if (isLoggedIn()) {
            alert('Please enter your email in the settings menu before using MY SCRIPT.');
            const logoutButton = document.querySelector('a[href="https://gamerlee.com/auth/logout"]');
            if (logoutButton) {
                logoutButton.click();
            } else {
                window.location.replace("https://gamerlee.com/auth/logout");
            }
        }
    }

    function enforceReferralUrl() {
        if (window.location.href.startsWith("https://gamerlee.com") && !window.location.href.includes("?r=1011")) {
            if (!isLoggedIn()) {
                window.location.replace("https://gamerlee.com/?r=1011");
            }
        }
    }

    function fillEmailField(email) {
        const emailInput = document.querySelector('input[type="email"]');
        if (emailInput) {
            emailInput.value = email;
            emailInput.dispatchEvent(new Event('input', { bubbles: true }));
        }
    }

    function isTurnstileCompleted() {
        return document.querySelector('input[name="cf-turnstile-response"]')?.value !== "";
    }

    function isEmailFilled() {
        const emailField = document.querySelector('input[type="email"]');
        return emailField && emailField.value.trim() !== "";
    }

    function clickLoginButton() {
        const loginButton = document.querySelector('button[type="submit"].btn-user');
        if (loginButton) {
            loginButton.click();
        }
    }

    const checkConditionsInterval = setInterval(function() {
        if (isTurnstileCompleted() && isEmailFilled()) {
            clearInterval(checkConditionsInterval);
            clickLoginButton();
        }
    }, 1000);

    const observer = new MutationObserver(() => {
        const emailInput = document.querySelector('input[type="email"]');
        if (emailInput) {
            const email = cfg.get('Email').trim();
            if (email) {
                fillEmailField(email);
            }
            observer.disconnect();
        }
    });

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

    const turnstileObserver = new MutationObserver(() => {
        const turnstileResponse = document.querySelector('input[name="cf-turnstile-response"]');
        if (turnstileResponse && turnstileResponse.value !== "") {
            clickLoginButton();
            turnstileObserver.disconnect();
        }
    });

    const turnstileInput = document.querySelector('input[name="cf-turnstile-response"]');
    if (turnstileInput) {
        turnstileObserver.observe(turnstileInput, { attributes: true, attributeFilter: ['value'] });
    }

    const urls = [
        "https://gamerlee.com/faucet/currency/ltc",
        "https://gamerlee.com/faucet/currency/btc",
        "https://gamerlee.com/faucet/currency/bnb",
        "https://gamerlee.com/faucet/currency/dash",
        "https://gamerlee.com/faucet/currency/doge",
        "https://gamerlee.com/faucet/currency/eth",
        "https://gamerlee.com/faucet/currency/dgb",
        "https://gamerlee.com/faucet/currency/xrp",
        "https://gamerlee.com/faucet/currency/fey",
        "https://gamerlee.com/faucet/currency/tara",
        "https://gamerlee.com/faucet/currency/sol",
        "https://gamerlee.com/faucet/currency/usdt",
        "https://gamerlee.com/faucet/currency/xlm",
        "https://gamerlee.com/faucet/currency/ada",
        "https://gamerlee.com/faucet/currency/trx",
        "https://gamerlee.com/faucet/currency/xmr",
        "https://gamerlee.com/faucet/currency/zec"
    ];

    let currentIndex = parseInt(localStorage.getItem('currentIndex')) || 0;

    const rotateUrls = () => {
        if (window.location.href === "https://gamerlee.com/" || window.location.href.includes("/dashboard")) {
            window.location.href = urls[currentIndex];
            currentIndex = (currentIndex + 1) % urls.length;
            localStorage.setItem('currentIndex', currentIndex);
        }
    };

    const scrollToButton = () => {
        const submitButton = document.querySelector("#subbutt");
        if (submitButton) {
            const isVisible = () => {
                const rect = submitButton.getBoundingClientRect();
                return (
                    rect.top >= 0 &&
                    rect.left >= 0 &&
                    rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
                    rect.right <= (window.innerWidth || document.documentElement.clientWidth)
                );
            };
            if (!isVisible()) {
                submitButton.scrollIntoView({
                    behavior: 'smooth',
                    block: 'center'
                });
            }
        }
    };
    scrollToButton();

    function checkTurnstile() {
        const turnstileResponse = document.querySelector('input[name="cf-turnstile-response"]');
        return turnstileResponse && turnstileResponse.value !== '';
    }

    function checkRecaptcha() {
        const recaptchaFrame = document.querySelector("iframe[title='reCAPTCHA']");
        if (recaptchaFrame) {
            return window.grecaptcha.getResponse().length !== 0;
        }
        return false;
    }

    function clickClaimNow() {
        const claimNowButton = document.querySelector('#subbutt');
        if (claimNowButton && claimNowButton.innerText.includes('Claim Now')) {
            claimNowButton.click();
        }
    }

    function clickUnlock() {
        const unlockButton = document.querySelector('button.btn.btn-primary.w-md');
        if (unlockButton && unlockButton.innerText.includes('Unlock')) {
            unlockButton.click();
        }
    }

    let intervalId = setInterval(() => {
        if (checkTurnstile() || checkRecaptcha()) {
            clickClaimNow();
            clickUnlock();
            clearInterval(intervalId);
            clearTimeout(timeoutId);
        }
    }, 1000);

    let timeoutId = setTimeout(() => {
        clickClaimNow();
        clickUnlock();
        clearInterval(intervalId);
    }, 45000);

    function checkForMessage() {
    const swalContainer = document.querySelector('#swal2-html-container');
    const alertDanger = document.querySelector('.alert.alert-danger.text-center');
    const alertSuccess = document.querySelector('.alert.alert-success.text-center');
    if (swalContainer && swalContainer.style.display === 'block') {
        const pageText = swalContainer.innerText || "";
        const successMessage1 = "has been sent to your FaucetPay account!";
        const successMessage2 = "has been added to your Main account!";
        const successMessage3 = "The faucet does not have sufficient funds for this transaction.";
        const invalidCaptchaMessage = "Invalid Captcha";

        setTimeout(() => {
            if (pageText.includes(successMessage1) ||
                pageText.includes(successMessage2) ||
                pageText.includes(successMessage3) ||
                pageText.includes(invalidCaptchaMessage)) {
                    window.location.replace("https://gamerlee.com/dashboard");
            }
        }, 1000);
    }

    if (alertDanger) {
        const alertText = alertDanger.innerText || "";
        const dailyLimitMessage = "Daily claim limit for this coin reached, please comeback again tomorrow.";

        setTimeout(() => {
            if (alertText.includes(dailyLimitMessage)) {
                window.location.replace("https://gamerlee.com/dashboard");
            }
        }, 1000);
    }
}

setInterval(checkForMessage, 1000);

})();