ClaimFaucet.fun auto faucet

Automatically login and click faucet

// ==UserScript==
// @name         ClaimFaucet.fun auto faucet
// @namespace    auto faucet with rotator
// @version      0.2
// @description  Automatically login and click faucet
// @author       Ojo Ngono
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_addStyle
// @grant        window.onurlchange
// @grant        GM_registerMenuCommand
// @require      https://update.greasyfork.org/scripts/439099/1203718/MonkeyConfig%20Modern%20Reloaded.js
// @match        https://claimfaucet.fun/*
// @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(() => {
                clickLoginRegisterButton();
            }, 1000);

            const loginInterval = setInterval(() => {
                handleLoginPopup();
            }, 1000);

            setTimeout(() => {
                clearInterval(loginInterval);
                if (document.querySelector("#logoutModal")) {
                    rotateUrls();
                    checkTurnstileAndClick();
                }
            }, 500);
        }
    });

    function enforceReferralUrl() {
        if (window.location.href === "https://claimfaucet.fun" && !window.location.href.includes("?r=1242")) {
            const loggedIn = document.querySelector("#logoutModal");
            if (!loggedIn) {
                window.location.replace("https://claimfaucet.fun/?r=1242");
            }
        }
    }

    function enforceLogoutWithWarning() {
        const loggedIn = document.querySelector("#logoutModal");
        if (loggedIn) {
            alert('Please enter your email in the settings menu before using my script.');
            const logoutButton = document.querySelector('a[href="https://claimfaucet.fun/auth/logout"]');
            if (logoutButton) {
                logoutButton.click();
            } else {
                window.location.replace("https://claimfaucet.fun/auth/logout");
            }
        }
    }

    function clickLoginRegisterButton() {
        const loginButton = document.querySelector('span.mb-0');
        if (loginButton && loginButton.textContent.includes('Login / Register')) {
            loginButton.click();
        }
    }

    function handleLoginPopup() {
        const modalTitle = document.querySelector('.modal-title');
        if (modalTitle && modalTitle.textContent.includes('Login')) {
            const emailInput = document.querySelector('#InputEmail');
            if (emailInput) {
                emailInput.value = cfg.get('Email');
                console.log('Email filled:', emailInput.value);
            }
            const loginButton = document.querySelector('button[type="submit"].d-flex.align-items-center.btn.btn-outline.border.text-secondary');
            const checkCaptchaAndLogin = setInterval(() => {
                const captchaResponse = document.querySelector('textarea[name="g-recaptcha-response"]');
                if (captchaResponse && captchaResponse.value.trim().length > 0) {
                    loginButton.click();
                    clearInterval(checkCaptchaAndLogin);
                } else {
                }
            }, 1000);
        }
    }

    const urls = [
        "https://claimfaucet.fun/faucet/currency/bnb",
        "https://claimfaucet.fun/faucet/currency/btc",
        "https://claimfaucet.fun/faucet/currency/bch",
        "https://claimfaucet.fun/faucet/currency/dash",
        "https://claimfaucet.fun/faucet/currency/dgb",
        "https://claimfaucet.fun/faucet/currency/eth",
        "https://claimfaucet.fun/faucet/currency/fey",
        "https://claimfaucet.fun/faucet/currency/ltc",
        "https://claimfaucet.fun/faucet/currency/matic",
        "https://claimfaucet.fun/faucet/currency/sol",
        "https://claimfaucet.fun/faucet/currency/trx",
        "https://claimfaucet.fun/faucet/currency/usdt",
        "https://claimfaucet.fun/faucet/currency/xrp",
        "https://claimfaucet.fun/faucet/currency/zec"
    ];
    let currentIndex = parseInt(localStorage.getItem('currentIndex')) || 0;
    const rotateUrls = () => {
        if (window.location.href === "https://claimfaucet.fun/") {
            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() {
        let turnstileResponse = document.querySelector('input[name="cf-turnstile-response"]');
        return turnstileResponse && turnstileResponse.value !== '';
    }

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

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

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

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

    function checkForMessage() {
        const swalContainer = document.querySelector('#swal2-html-container');
        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 = "You are sending an invalid amount of payment to the user.";
            const successMessage4 = "The faucet does not have sufficient funds for this transaction.";
            const invalidCaptchaMessage = "Invalid Captcha";
            setTimeout(() => {
                const cleanedText = cleanText(pageText);
                if (cleanedText.includes(successMessage1) || cleanedText.includes(successMessage2) || cleanedText.includes(successMessage3) || cleanedText.includes(successMessage4) || cleanedText.includes(invalidCaptchaMessage)) {
                    window.location.replace("https://claimfaucet.fun/");
                } else {
                }
            }, 1000);
        } else {
        }
    }

    function cleanText(text) {
        return text.replace(/\s+/g, ' ').trim();
    }

    setInterval(checkForMessage, 1000);

})();