Auto Click Cloudflare CAPTCHA

Automatically click Cloudflare CAPTCHA checkbox (iframe version)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Auto Click Cloudflare CAPTCHA
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  Automatically click Cloudflare CAPTCHA checkbox (iframe version)
// @author       Zaw (based on NWater)
// @match        https://challenges.cloudflare.com/cdn-cgi/challenge-platform/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    function waitFor(selector, timeout = 20000) {
        return new Promise((resolve, reject) => {
            const start = Date.now();
            const interval = setInterval(() => {
                const el = document.querySelector(selector);
                if (el && el.offsetParent !== null && !el.disabled) {
                    clearInterval(interval);
                    resolve(el);
                } else if (Date.now() - start > timeout) {
                    clearInterval(interval);
                    reject("Timeout waiting for " + selector);
                }
            }, 300);
        });
    }

    async function autoClickCaptcha() {
        try {
            console.log("[AutoCaptcha] Waiting for checkbox...");
            const checkbox = await waitFor("input[type='checkbox']");
            checkbox.click();
            console.log("[AutoCaptcha] Checkbox clicked.");

            const mark = await waitFor("span.mark");
            mark.click();
            console.log("[AutoCaptcha] Mark clicked.");
        } catch (err) {
            console.warn("[AutoCaptcha] Failed:", err);
        }
    }

    if (document.readyState === "loading") {
        document.addEventListener("DOMContentLoaded", autoClickCaptcha);
    } else {
        autoClickCaptcha();
    }
})();