Onlyfaucet Auto Faucet

Automatically Login and Click Faucet

// ==UserScript==
// @name         Onlyfaucet Auto Faucet
// @namespace    bekerja pada tampermonkey maupun violentmonkey
// @version      0.2
// @autor        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        *://onlyfaucet.com/*
// @antifeature  referral-link Directs to a referral link when not logged in
// @license      Copyright OjoNgono
// ==/UserScript==

const cfg = new MonkeyConfig({
    title: 'Input Email Faucetpay:',
    menuCommand: true,
    params: {
        Announcements: {
            type: 'text',
            default: 'Input Email Faucetpay',
            long: 3
        },
        Email: {
            label: "EmailFaucetpay",
            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);
                startClaimProcess();
            }, 10000);
        }
    });

    function enforceReferralUrl() {
        const url = window.location.href;
        if (url.startsWith("https://onlyfaucet.com/") && !url.includes("?r=29298")) {
            const loggedIn = document.querySelector("#logoutModal");
            if (!loggedIn) {
                window.location.replace("https://onlyfaucet.com/?r=29298");
            }
        }
    }

    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://onlyfaucet.com/auth/logout"]');
            if (logoutButton) {
                logoutButton.click();
            } else {
                window.location.replace("https://onlyfaucet.com/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');
            }
            const continueButton = document.querySelector('button[type="submit"].d-flex.align-items-center.btn.btn-outline.border.text-secondary');
            if (continueButton) {
                continueButton.click();
            } 
        }
    }

    function startClaimProcess() {
    }

    function waitForElement(selector, callback) {
        const observer = new MutationObserver((mutations, obs) => {
            if (document.querySelector(selector)) {
                callback();
                obs.disconnect();
            }
        });
        observer.observe(document, {
            childList: true,
            subtree: true
        });
    }

    if (window.location.href.includes("https://onlyfaucet.com/faucet/currency/")) {
        waitForElement('#subbutt', () => {
            const button = document.querySelector('#subbutt');
            if (button) {
             setTimeout(() => {
                button.click();
                    startClaimProcess();
                }, 2000);
            }
        });
    }

    function checkForMessage() {
        const swalContainer = document.querySelector('#swal2-html-container');
        if (swalContainer && swalContainer.style.display === 'block') {
            const pageText = swalContainer.innerText || "";
            const targetMessage = "You must complete at least 1 Shortlink to continue";
            if (cleanText(pageText).includes(targetMessage)) {
                setTimeout(() => {
                    const currentUrl = window.location.href;
                    const match = currentUrl.match(/https:\/\/onlyfaucet.com\/faucet\/currency\/(\w+)/);
                    if (match) {
                        const currency = match[1]; 
                        window.location.href = `https://onlyfaucet.com/links/currency/${currency}`;
                    }
                }, 1000); 
            }
        }
    }

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

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