PixelPlanet Clones Captcha Solver

Solve PixelPlanet clones captchas automatically (Supported: pixmap, globalpixel, pixelya, chillpixel)

目前为 2024-11-22 提交的版本。查看 最新版本

// ==UserScript==
// @name         PixelPlanet Clones Captcha Solver
// @namespace    vermei_and_nof
// @version      1.3
// @description  Solve PixelPlanet clones captchas automatically (Supported: pixmap, globalpixel, pixelya, chillpixel)
// @match        https://pixmap.fun/*
// @match        https://globepixel.fun/*
// @match        https://pixelya.fun/*
// @match        https://chillpixel.xyz/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    const site = window.location.host;
    const path = site == 'pixelya.fun' ? 'div.CaptchaAlert.show' : 'div.Alert.show';
    console.log(site);
    function sleep(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
}

    function do_url_to_svg(url) {
        return fetch(url)
            .then(function(response) {
                if (response.status !== 200) {
                    console.log('Looks like there was a problem. Status Code: ' + response.status);
                    return;
                }
                return response.text();
            })
            .catch(function(err) {
                console.log('Fetch Error :-S', err);
            });
    }

    function solveCaptcha() {
        const captchaElement = document.querySelector(`#app > ${path} > form > div > img`);
        const url = captchaElement.src;

        const svgelement = do_url_to_svg(url);

        svgelement.then(function(svgData) {
            const postData = {
                data:[svgData.replace(/stroke="#{0,1}\S+"/, 'stroke="black"').replace(/stroke-width: \d+;/, 'stroke-width: 4;')]
            };

            fetch('https://fuururuny-pixmap-captcha.hf.space/gradio_api/call/predict', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(postData)
            })
            .then(function(response) {
                if (response.status !== 200) {
                    console.log('Looks like there was a problem. Status Code: ' + response.status);
                    return;
                }
                response.json().then(function(data) {
                    const eventID = data.event_id;
                    fetch(`https://fuururuny-pixmap-captcha.hf.space/gradio_api/call/predict/${eventID}`, {
                        method: 'GET'
                    })
                    .then(function(response) {
                        if (response.status !== 200) {
                            console.log('Looks like there was a problem. Status Code: ' + response.status);
                            return;
                        }
                        response.text().then(function(data) {
                            const answer = data.match(/"([^"]+)"/)[1];
                            const captchafield = document.querySelector(`#app > ${path} > form input[name='captcha']`);
                            captchafield.value = answer;
                            console.log(answer);
                            const sendcaptcha = document.querySelector(`#app > ${path} > form button[type="submit"]`);
                            sendcaptcha.click();
                        });
                    })
                    .catch(function(err) {
                        console.log('Fetch Error :-S', err);
                    });
                });
            })
            .catch(function(err) {
                console.log('Fetch Error :-S', err);
            });
        });
    }

    const observer = new MutationObserver(function(mutationsList, observer) {
        for (let mutation of mutationsList) {
            if (mutation.target.querySelector('img')) {
                solveCaptcha();
                observer.disconnect();
                observer.observe(document.documentElement, { childList: true, subtree: true });
                break;
            }
        }
    });

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

})();