CloudFlare Challenge Optimized

Automates solving Cloudflare Challenges with optimal performance and maintainability

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         CloudFlare Challenge Optimized
// @version      0.3
// @description  Automates solving Cloudflare Challenges with optimal performance and maintainability
// @author       AstralRift
// @namespace    https://greatest.deepsurf.us/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();
})();