CloudFlare Challenge Optimized

Automates solving Cloudflare Challenges with optimal performance and maintainability

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         CloudFlare Challenge Optimized
// @version      0.3
// @description  Automates solving Cloudflare Challenges with optimal performance and maintainability
// @author       AstralRift
// @namespace    https://greasyfork.org/users/1300060
// @match        https://challenges.cloudflare.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    let observer = null;
    let intervalId = null;

    function attemptChallenge() {
        const targets = [
            "#cf-stage > div.ctp-checkbox-container > label > span",
            "input[value='Verify you are human']",
            ".ctp-checkbox-label"
        ];

        for (let selector of targets) {
            const element = document.querySelector(selector);
            if (element) {
                element.click();
                return true;
            }
        }
        return false;
    }

    function setupObserver() {
        observer = new MutationObserver(() => {
            if (attemptChallenge()) {
                disconnectObserver();
                clearInterval(intervalId);
            }
        });

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

    function disconnectObserver() {
        if (observer) {
            observer.disconnect();
            observer = null;
        }
    }

    function setupInterval() {
        const intervalFunction = () => {
            if (attemptChallenge()) {
                clearInterval(intervalId);
                disconnectObserver();
            }
        };

        intervalId = setInterval(intervalFunction, 1000);

        setTimeout(() => {
            clearInterval(intervalId);
            disconnectObserver();
        }, 60000);
    }

    function handleChallenge() {
        if (!attemptChallenge()) {
            setupObserver();
            setupInterval();
        }
    }

    handleChallenge();
})();