NitroType leagues XP-races

Script that shows how many races you need to beat player above you in league (approximately)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         NitroType leagues XP-races
// @namespace    http://tampermonkey.net/
// @version      v2
// @description  Script that shows how many races you need to beat player above you in league (approximately)
// @author       dphdmn
// @match        https://www.nitrotype.com/leagues
// @icon         https://www.google.com/s2/favicons?sz=64&domain=nitrotype.com
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    function intNum(input) {
        // Remove all commas using the replace method and parse the result as an integer
        const number = parseInt(input.replace(/,/g, ''), 10);
        return isNaN(number) ? null : number; // Return null if the input is not a valid number
    }
    // Function to get the text content of the "self" element
    function getSelfXP() {
        const selfElement = document.querySelector('tr.table-row.is-self td.table-cell.leagues--standings--experience');
        if (selfElement) {
            return intNum(selfElement.textContent.trim());
        } else {
            return null;
        }
    }
    function getSelfRaces() {
        const selfElement = document.querySelector('tr.table-row.is-self td.table-cell.leagues--standings--played');
         if (selfElement) {
            return intNum(selfElement.textContent.trim());
        } else {
            return null;
        }
    }

    // Function to get all elements that match the criteria
    function getAllElementsXP() {
        const elements = document.querySelectorAll('td.table-cell.leagues--standings--experience');
        return elements;
    }

    // Function to initialize after the page has fully loaded
    function initialize() {
        const interval = setInterval(() => {
            const selfXP = getSelfXP();
            const selfRaces = getSelfRaces()
            const allXP = getAllElementsXP();

            // Check if both the selfXP and allXP are non-empty
            if (selfXP && allXP.length > 0) {
                const xpRatio = selfXP/selfRaces;

                allXP.forEach((element, index) => {
                    const xpValue = intNum(element.textContent.trim());
                    const racesToMatch = Math.ceil(xpValue / xpRatio);
                    const racesDifference = racesToMatch - selfRaces;
                    if (selfXP != xpValue) {
                        if (selfXP > xpValue) {
                            element.innerHTML = element.textContent + "<br><span style=\"font-size: 14px; color: red;\">" + racesDifference + "</span>";
                        } else {
                            element.innerHTML = element.textContent + "<br><span style=\"font-size: 14px; color: cyan;\">+" + racesDifference + "</span>";
                        }
                    }
                });

                clearInterval(interval);
            }
        }, 100);
    }

    // Wait for the page to load before starting the interval check
    window.addEventListener('load', initialize);
    document.getElementById("showindividual").addEventListener('click', initialize);
    document.getElementById("showteam").addEventListener('click', initialize);


})();