Chess.com AutoMove with Stockfish 17.1 (Fast Start)

Automatically plays Stockfish 17.1 moves instantly on Chess.com (bot games only)

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Chess.com AutoMove with Stockfish 17.1 (Fast Start)
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically plays Stockfish 17.1 moves instantly on Chess.com (bot games only)
// @match        https://www.chess.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // 🧠 Use Stockfish 17.1 (WASM build — host your own or use a trusted CDN)
    const STOCKFISH_URL = 'https://lichess1.org/assets/engine/stockfish.wasm.js'; // Lichess-hosted (version may vary)

    let stockfish;
    let running = false;

    function initStockfish() {
        stockfish = new Worker(STOCKFISH_URL);
        stockfish.postMessage("uci");
    }

    function getFEN() {
        try {
            const game = window?.CHESS?.getGameData?.();
            if (game?.fen && !game.gameOver) return game.fen;
        } catch (e) {}
        return null;
    }

    function doMove(uci) {
        const from = uci.slice(0, 2);
        const to = uci.slice(2, 4);
        const fromSquare = document.querySelector(`[data-square='${from}']`);
        const toSquare = document.querySelector(`[data-square='${to}']`);
        if (fromSquare && toSquare) {
            fromSquare.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
            toSquare.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }));
        }
    }

    function startAutoMove() {
        if (running) return;
        running = true;

        stockfish.onmessage = function (e) {
            const msg = e.data;
            if (typeof msg === "string" && msg.startsWith("bestmove")) {
                const move = msg.split(" ")[1];
                if (move && move.length >= 4) {
                    doMove(move);
                }
            }
        };

        setInterval(() => {
            const fen = getFEN();
            if (fen) {
                stockfish.postMessage(`position fen ${fen}`);
                stockfish.postMessage("go depth 12");
            }
        }, 1500); // every 1.5 sec
    }

    // 🧠 Start when DOM is ready
    window.addEventListener("load", () => {
        initStockfish();
        startAutoMove();
    });
})();