NitroType Perfect Nitros with SFB Highlight (QWERTY, DVORAK, COLEMAK)

Highlights the largest words and single-finger bigrams (SFBs) for QWERTY, DVORAK, or COLEMAK layouts

当前为 2024-10-19 提交的版本,查看 最新版本

// ==UserScript==
// @name         NitroType Perfect Nitros with SFB Highlight (QWERTY, DVORAK, COLEMAK)
// @namespace    https://gf.qytechs.cn/users/1331131-tensorflow-dvorak
// @version      2.0.0
// @description  Highlights the largest words and single-finger bigrams (SFBs) for QWERTY, DVORAK, or COLEMAK layouts
// @author       Ray Adams/Nate Dogg / TensorFlow - Dvorak
// @match        https://www.nitrotype.com/race
// @match        https://www.nitrotype.com/race/*
// @run-at       document-end
// @grant        none
// @license      MIT
// ==/UserScript==

(() => {
    // CHANGE THIS to 'QWERTY', 'DVORAK' or 'COLEMAK' as needed
    const keyboardLayout = 'QWERTY';

    const options = {
        highlightColor: '#1b1c25',
        singleFingerBigramColor: 'yellow',
        intervalMs: 100
    };

    // SFBs for different keyboard layouts. Replace with only what you want to work on.
    const SFBs = new Map([
        ['QWERTY', ['ed', 'de', 'fr', 'rf', 'gt', 'tg', 'bv', 'vb', 'ju', 'uj', 'ki', 'ik', 'lo', 'ol', 'nm', 'mn', 'nu', 'un']],
        ['DVORAK', ['gh', 'pu', 'up', 'ui', 'iu', 'pi', 'ip']],
        ['COLEMAK', ['']] // Do it yourself
    ]);

    const client = () => {
        const dashLetters = document.querySelector('.dash-letter');
        if (dashLetters) {
            clearInterval(intervalId);

            // Get all words from the race
            const wordList = [...document.getElementsByClassName('dash-word')].map(word => word.textContent.replace(/\s/g, ''));

            // Find the largest words
            const maxLength = Math.max(...wordList.map(word => word.length));
            const largestWords = wordList.filter(word => word.length === maxLength);

            // Highlight largest words and bigrams
            wordList.forEach((word, index) => {
                const wordElement = document.getElementsByClassName('dash-word')[index];
                if (largestWords.includes(word)) {
                    wordElement.style.backgroundColor = options.highlightColor;
                }
                highlightSingleFingerBigrams(wordElement);
            });
        }
    };

    const highlightSingleFingerBigrams = (wordElement) => {
        const text = wordElement.textContent;

        // Loop over the text and highlight single-finger bigrams using CSS
        for (let i = 0; i < text.length - 1; i++) {
            const bigram = text[i] + text[i + 1];
            if (SFBs.get(keyboardLayout).includes(bigram)) {
                wordElement.querySelector(`.dash-letter:nth-child(${i + 1})`).style.color = options.singleFingerBigramColor;
                wordElement.querySelector(`.dash-letter:nth-child(${i + 2})`).style.color = options.singleFingerBigramColor;
                i++;
            }
        }
    };

    const intervalId = setInterval(client, options.intervalMs);

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址