Claim.ourCoinCash.xyz AutoClaim Faucet

Automatically Login and Click Faucet

// ==UserScript==
// @name         Claim.ourCoinCash.xyz AutoClaim Faucet
// @namespace    bekerja pada tampermonkey maupun violentmonkey
// @version      0.8
// @author       Ojo Ngono
// @description  Automatically Login and Click Faucet
// @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        *://claim.ourcoincash.xyz/*
// @exclude      https://claim.ourcoincash.xyz/auth/login*
// @license      Copyright OjoNgono
// @antifeature  referral-link Directs to a referral link when not logged in
// ==/UserScript==

(function () {
    'use strict';

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

    window.addEventListener('load', () => {
        const email = cfg.get('Email').trim();
        if (!email) {
            enforceLogoutWithWarning();
            return;
        }
        if (!isValidEmail(email)) {
            alert('Invalid email address. Please check your configuration.');
            enforceLogoutWithWarning();
            return;
        }
        if (isLoggedIn()) {
            if (isFaucetPage()) {
                checkGoClaimButton();
                autoClickClaimButton();
            } else {
                window.location.replace("https://claim.ourcoincash.xyz/faucet/currency/doge");
            }
        } else {
            setTimeout(() => {
                enforceReferralUrl(() => {
                    fillEmailField(email);
                    setTimeout(() => {
                        clickLoginButton();
                    }, 2000); 
                });
            }, 1000); 
        }
        const currentCoin = window.location.href.includes("doge") ? "doge" : "ltc";
        redirectIfLimitReached(currentCoin);
        autoClickClaimButton();
        checkAndClickTryAgain();
    });

    function isLoggedIn() {
        return !!document.querySelector('i.fas.fa-user-circle.fa-2x');
    }

    function isValidEmail(email) {
        const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
        return emailRegex.test(email);
    }

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

    function enforceReferralUrl(callback) {
        if (!window.location.href.includes("?r=5848")) {
            window.location.replace("https://claim.ourcoincash.xyz/?r=5848");
            setTimeout(callback, 1000);
        } else {
            callback();
        }
    }

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

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

    function isFaucetPage() {
        return window.location.href.includes("/faucet/currency/");
    }

    function autoClickClaimButton() {
        const claimButton = document.getElementById('subbutt');
        if (claimButton && claimButton.classList.contains('btn-primary')) {
            setTimeout(() => {
                claimButton.click();
            }, 1000);
        }
    }

    function checkGoClaimButton() {
        const goClaimButton = document.querySelector('h4.next-button a.btn.btn-primary');
        if (goClaimButton && goClaimButton.textContent.trim() === "Go Claim") {
            setTimeout(() => {
                window.location.reload();
            }, 1000);
        }
    }

    function checkAndClickTryAgain() {
        const networkErrorMessage = document.querySelector('h2.title-xl-grad');
        const tryAgainButton = document.querySelector('.btn.btn-primary');
        if (networkErrorMessage && tryAgainButton && networkErrorMessage.textContent.trim() === "Network Error") {
            tryAgainButton.click();
        }
    }

    const observer = new MutationObserver(() => {
        checkGoClaimButton();
        checkAndClickTryAgain();
    });

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

    function redirectIfLimitReached(coin) {
        if (!window.location.href.includes(`/faucet/currency/${coin}`)) return;
        setTimeout(() => {
            const alertMessage = document.querySelector('.alert.alert-danger.text-center');
            const swalPopup = document.querySelector('.swal2-popup.swal2-show');
            if (
                (alertMessage && alertMessage.textContent.includes("Daily claim limit for this coin reached")) ||
                (swalPopup && swalPopup.textContent.includes("The faucet does not have sufficient funds for this transaction."))
            ) {
                if (coin === "ltc") {
                    return; 
                }
                const nextCoin = coin === "doge" ? "ltc" : "doge";
                window.location.replace(`https://claim.ourcoincash.xyz/faucet/currency/${nextCoin}`);
            }
        }, 1000);
    }

    function clickOkButtonAfterDelay() {
        const okButton = document.querySelector('.swal2-confirm');
        if (okButton) {
            setTimeout(() => {
                okButton.click();
            }, 2000);
        }
    }

    clickOkButtonAfterDelay();
})();