10FastFingers correcter

Each key types the correct letter.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         10FastFingers correcter
// @namespace    http://tampermonkey.net/
// @version      2.1
// @description  Each key types the correct letter.
// @author       Kakoncheater
// @match        https://10ff.net/*
// @match        https://10fastfingers.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function findInput() {
        return document.querySelector('#word-input') ||
               document.querySelector('input[type="text"]') ||
               document.querySelector('input');
    }

    document.addEventListener('keydown', function(e) {
        const inputField = findInput();

        if (!inputField || document.activeElement !== inputField) return;

        if (e.key === 'Backspace' || e.key === 'Control' || e.key === 'Alt' ||
            e.key === 'Shift' || e.key === 'Tab' || e.key === 'Enter') {
            return;
        }

        const highlight = document.querySelector('.highlight');

        if (highlight) {
            e.preventDefault();

            const targetWord = highlight.textContent;
            const currentVal = inputField.value;

            if (currentVal === targetWord) {
                inputField.value += " ";
                const eventInput = new Event('input', { bubbles: true });
                inputField.dispatchEvent(eventInput);

                const eventDown = new KeyboardEvent('keydown', {'key':' ', 'code':'Space', 'keyCode':32, 'which':32, 'bubbles':true});
                inputField.dispatchEvent(eventDown);

                const eventUp = new KeyboardEvent('keyup', {'key':' ', 'code':'Space', 'keyCode':32, 'which':32, 'bubbles':true});
                inputField.dispatchEvent(eventUp);
            }
            else if (currentVal.length < targetWord.length) {
                inputField.value += targetWord[currentVal.length];
                const event = new Event('input', { bubbles: true });
                inputField.dispatchEvent(event);
            }
        }
    });

})();