Nitro Type Perfect Nitros By MV Typing

Highlights the largest words for perfect nitros. 2nd version which makes the highlighted word black so it would look better. Enjoy!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @license      MIT
// @name         Nitro Type Perfect Nitros By MV Typing
// @namespace    https://youtube.com/@mvtyping
// @version      3.0.0
// @description  Highlights the largest words for perfect nitros. 2nd version which makes the highlighted word black so it would look better. Enjoy!
// @author       MV Typing
// @match        https://www.nitrotype.com/race
// @match        https://www.nitrotype.com/race/*
// @run-at       document-end
// @grant        none
// ==/UserScript==

(() => {

    const options = {
        highlightColor: 'black',
        intervalMs: 100
    };

    const client = () => {

        if (document.body.contains(document.querySelector('.dash-letter'))) {

            clearInterval(intervalId);

            // Generate word list from DOM
            let wordList = []
            for (let words of document.getElementsByClassName('dash-word')) {
                wordList.push(
                    words.textContent.replace(/\s/g, '')
                )
            }

            // Find the largest words
            let largestWords = [];
            for (let word of wordList) {
                if (typeof largestWords[0] === 'undefined' || largestWords[0].length === word.length) {
                    largestWords.push(word);
                }

                if (word.length > largestWords[0].length) {
                    largestWords = [word];
                }
            }

            // Return all occurrences of a specific value
            Array.prototype.indexesOf=function(t){for(var r=[],n=this.length-1;0<=n;n--)this[n]===t&&r.unshift(n);return r};

            // Find the indexes of the largest words in wordList
            let largestWordIndexes = []
            for (let values of wordList.values()) {
                if (largestWords.includes(values)) largestWordIndexes.push(
                    wordList.indexesOf(values)
                )
            }

            // Flatten array and remove duplicate values
            largestWordIndexes = [...new Set(largestWordIndexes.flat())];

            // Highlight largest words
            for (let indexes of largestWordIndexes) {
                document.getElementsByClassName('dash-word')[indexes].style.backgroundColor = options.highlightColor
            }

        }

    }

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

    console.info('Perfect Nitros Activated.')

})()