Greasy Fork is available in English.

Cryptocoil Auto Faucet

Automatically Login and Click Faucet

// ==UserScript==
// @name         Cryptocoil 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        https://cryptocoil.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://cryptocoil.com/") && !url.includes("?r=36")) {
            const loggedIn = document.querySelector("#logoutModal");
            if (!loggedIn) {
                window.location.replace("https://cryptocoil.com/?r=36");
            }
        }
    }

    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://cryptocoil.com/auth/logout"]');
            if (logoutButton) {
                logoutButton.click();
            } else {
                window.location.replace("https://cryptocoil.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');
        }

        waitForAuthKong(() => {
            const continueButton = document.querySelector('button[type="submit"].d-flex.align-items-center.btn.btn-outline.border.text-secondary');
            if (continueButton) {
                continueButton.click();
            }
        });
    }
}

function waitForAuthKong(callback) {
    const captchaResponse = document.querySelector('input[name="captcha-response"]');

    const interval = setInterval(() => {
        if (captchaResponse && captchaResponse.value.trim() !== '') {
            clearInterval(interval);
            callback();
        }
    }, 500);

    setTimeout(() => {
        clearInterval(interval);
    }, 30000);
}

    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://cryptocoil.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:\/\/cryptocoil.com\/faucet\/currency\/(\w+)/);
                    if (match) {
                        const currency = match[1];
                        window.location.href = `https://cryptocoil.com/links/currency/${currency}`;
                    }
                }, 1000);
            }
        }
    }

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

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