Greasy Fork 还支持 简体中文。

Chess.com Anti-Misclick

Ajoute un délai anti-misclick sur Chess.com avec bouton d'activation

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Chess.com Anti-Misclick
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Ajoute un délai anti-misclick sur Chess.com avec bouton d'activation
// @author       Yglsan
// @match        https://www.chess.com/*
// @grant        GM_setValue
// @grant        GM_getValue
// @license      OpenGPL 3.0
// ==/UserScript==

(function() {
    'use strict';

    let selectedSquare = null;
    let lastClickTime = 0;
    const clickDelay = 750; // Délai en millisecondes
    const highlightColor = "rgba(255, 0, 0, 0.5)";
    let antiMisclickEnabled = GM_getValue("chessAntiMisclickEnabled", true);

    // Fonction de bascule
    function toggleMisclickProtection() {
        antiMisclickEnabled = !antiMisclickEnabled;
        GM_setValue("chessAntiMisclickEnabled", antiMisclickEnabled);
        updateButton();
    }

    // Mise à jour du bouton
    function updateButton() {
        const button = document.getElementById("chessAntiMisclickButton");
        if (!button) return;
        button.textContent = antiMisclickEnabled ? "🔴 Anti-Misclick ON" : "⚫ Anti-Misclick OFF";
        button.style.backgroundColor = antiMisclickEnabled ? "#28a745" : "#dc3545";
    }

    // Création du bouton
    function createButton() {
        const button = document.createElement("button");
        button.id = "chessAntiMisclickButton";
        button.textContent = antiMisclickEnabled ? "🔴 Anti-Misclick ON" : "⚫ Anti-Misclick OFF";
        Object.assign(button.style, {
            position: "fixed",
            bottom: "20px",
            right: "20px",
            zIndex: "9999",
            padding: "10px 15px",
            border: "none",
            borderRadius: "5px",
            color: "white",
            fontSize: "14px",
            cursor: "pointer",
            boxShadow: "2px 2px 10px rgba(0,0,0,0.3)",
            backgroundColor: antiMisclickEnabled ? "#28a745" : "#dc3545"
        });
        button.onclick = toggleMisclickProtection;
        document.body.appendChild(button);
    }

    // Gestion des clics
    function handleClick(event) {
        if (!antiMisclickEnabled) return;

        const square = event.target.closest('[data-piece], .square');
        if (!square) return;

        const now = Date.now();
        
        if (selectedSquare) {
            if (now - lastClickTime < clickDelay) {
                event.stopImmediatePropagation();
                event.preventDefault();
                resetSelection();
                console.log("Mouvement annulé (anti-misclick)");
                return false;
            }
            resetSelection();
        } else {
            selectedSquare = square;
            lastClickTime = now;
            highlightSquare(square);
            console.log("Sélection:", square);
        }
    }

    // Surbrillance
    function highlightSquare(square) {
        const originalBg = square.style.backgroundColor;
        square.style.backgroundColor = highlightColor;
        
        setTimeout(() => {
            if (square === selectedSquare) {
                square.style.backgroundColor = originalBg;
            }
        }, clickDelay);
    }

    // Réinitialisation
    function resetSelection() {
        if (selectedSquare) {
            selectedSquare.style.backgroundColor = "";
            selectedSquare = null;
        }
    }

    // Initialisation
    function init() {
        createButton();
        document.addEventListener('click', handleClick, true);
    }

    // Attente du chargement complet
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
})();