Chillfaucet.in auto faucet (not working)

Automatically Login and Click Faucet on Chillfaucet

// ==UserScript==
// @name         Chillfaucet.in auto faucet (not working)
// @namespace    bekerja pada tampermonkey maupun violentmonkey
// @version      0.3
// @description  Automatically Login and Click Faucet on Chillfaucet
// @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://chillfaucet.in/*
// @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', () => {
        startProcess();
    });

    function startProcess() {
        const email = cfg.get('Email');
        if (!email || email.trim() === '') {
            enforceLogoutWithWarning();
            return;
        } else {
            enforceReferralUrl();
            setTimeout(() => {
                if (!isLoggedIn()) {
                    clickLoginJoinButton();
                } else {
                    fillEmailField(email);
                    rotateUrls();
                    enforceReferralUrl();
                    observeTurnstileAndClaim();
                }
            }, 1000);
        }
    }

    function isLoggedIn() {
    const logoutMenuItem = document.querySelector('a[href="https://chillfaucet.in/auth/logout"]');
    const claimButton = document.querySelector('#subbutt');
    return logoutMenuItem !== null || claimButton !== 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://chillfaucet.in/auth/logout"]');
            if (logoutButton) {
                logoutButton.click();
            } else {
                window.location.replace("https://chillfaucet.in/auth/logout");
            }
        }
    }

    function enforceReferralUrl() {
        const email = cfg.get('Email');
        if (!isLoggedIn() && email) {
            const currentUrl = window.location.href;
            const referralUrl = "https://chillfaucet.in/?r=13464";
            if (currentUrl === "https://chillfaucet.in/" && !currentUrl.includes("?r=13464")) {
                window.location.replace(referralUrl);
            }
        }
    }

    function clickLoginJoinButton() {
        const loginButton = document.querySelector('a[data-target="#login"]');
        if (loginButton) {
            loginButton.click();
        }
        setTimeout(() => {
            const email = cfg.get('Email');
            fillEmailField(email);
            observeTurnstileAndClaim();
        }, 1000);
    }

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

    function observeTurnstileAndClaim() {
        const turnstileObserver = new MutationObserver(() => {
            const turnstileResponse = document.querySelector('input[name="cf-turnstile-response"]');
            const claimNowButton = document.querySelector('#subbutt');
            const modalSubmitButton = document.querySelector('.modal-footer button[type="submit"]');

            if (turnstileResponse && turnstileResponse.value !== "") {
                if (claimNowButton) {
                    claimNowButton.scrollIntoView({ behavior: 'smooth', block: 'center' });
                    claimNowButton.click();
                }
                if (modalSubmitButton) {
                    modalSubmitButton.scrollIntoView({ behavior: 'smooth', block: 'center' });
                    modalSubmitButton.click();
                }
                turnstileObserver.disconnect();
            }
        });

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

        setTimeout(() => {
            const turnstileResponse = document.querySelector('input[name="cf-turnstile-response"]');
            const claimNowButton = document.querySelector('#subbutt');
            const modalSubmitButton = document.querySelector('.modal-footer button[type="submit"]');

            if (turnstileResponse && turnstileResponse.value === "" && claimNowButton && claimNowButton.innerText.includes('Claim Now')) {
                claimNowButton.click();
            }
            if (modalSubmitButton) {
                modalSubmitButton.click();
            }
        }, 30000);
    }

    const urls = [
        "https://chillfaucet.in/faucet/currency/ltc",
        "https://chillfaucet.in/faucet/currency/doge",
        "https://chillfaucet.in/faucet/currency/trx",
        "https://chillfaucet.in/faucet/currency/usdt",
        "https://chillfaucet.in/faucet/currency/dgb",
        "https://chillfaucet.in/faucet/currency/bnb",
        "https://chillfaucet.in/faucet/currency/eth",
        "https://chillfaucet.in/faucet/currency/sol",
        "https://chillfaucet.in/faucet/currency/fey",
        "https://chillfaucet.in/faucet/currency/bch",
        "https://chillfaucet.in/faucet/currency/ton",
        "https://chillfaucet.in/faucet/currency/tara",
        "https://chillfaucet.in/faucet/currency/ada",
        "https://chillfaucet.in/faucet/currency/matic",
        "https://chillfaucet.in/faucet/currency/usdc",
        "https://chillfaucet.in/faucet/currency/xlm",
        "https://chillfaucet.in/faucet/currency/xmr",
        "https://chillfaucet.in/faucet/currency/xrp",
        "https://chillfaucet.in/faucet/currency/dash",
        "https://chillfaucet.in/faucet/currency/zec"
    ];
    let currentIndex = parseInt(localStorage.getItem('currentIndex')) || 0;

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

    function checkForMessage() {
        const swalPopup = document.querySelector('.swal2-popup.swal2-show');
        if (swalPopup) {
            const successMessageContainer = swalPopup.querySelector('.swal2-html-container');
            if (successMessageContainer) {
                const successMessage = successMessageContainer.innerText || "";
                const successIndicator = "has been sent to your FaucetPay account!";
                const claimSuccessIndicator = "Success!";
                const insufficientFundsMessage = "The faucet does not have sufficient funds for this transaction.";
                if (successMessage.includes(successIndicator) || successMessage.includes(claimSuccessIndicator)) {
                    window.location.href = "https://chillfaucet.in/";
                } else if (successMessage.includes(insufficientFundsMessage)) {
                    window.location.href = "https://chillfaucet.in/";
                }
            }
        }
    }

    setInterval(checkForMessage, 1000);
})();