getVaptchaCode

vaptcha-iframe 依赖库

สคริปต์นี้ไม่ควรถูกติดตั้งโดยตรง มันเป็นคลังสำหรับสคริปต์อื่น ๆ เพื่อบรรจุด้วยคำสั่งเมทา // @require https://update.greasyfork.org/scripts/418420/878837/getVaptchaCode.js

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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!)

/**
 * getVaptchaCode v1.0
 * @author Jixun<https://jixun.moe/>
 * @license BSD-3-Clause
 */

function getVaptchaCode(frameURL, container) {
    return new Promise((resolve) => {
        const {origin} = new URL(frameURL);
        const id = 'id' + Date.now() + Math.random();
        const frame = document.createElement('iframe');
        frame.style.transition = 'opacity 1s 1s';
        frame.style.opacity = 1;

        const eventHandler = (event) => {
            if (event.data.vaptcha === id) {
                resolve(event.data.token);
                window.removeEventListener('message', eventHandler);
                frame.style.opacity = 0;

                // Remove iframe after fadeout effects.
                setTimeout(() => {
                    if (frame.parentNode) {
                        frame.parentNode.removeChild(frame);
                    }
                }, 1000);
            }
        };

        window.addEventListener('message', eventHandler);

        frame.src = frameURL;
        frame.onload = () => {
            frame.contentWindow.postMessage({ vaptcha: 'init', id }, origin);
        };
        container.appendChild(frame);
    });
}