Nitro Type Current Session Display

Display current session information on Nitro Type pages

目前為 2024-03-23 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Nitro Type Current Session Display
// @version      0.5
// @description  Display current session information on Nitro Type pages
// @author       Cortezz
// @match        https://www.nitrotype.com/*
// @grant        GM_xmlhttpRequest
// @namespace none
// ==/UserScript==

(function() {
    'use strict';

    // Create HTML element to display current session information
    var sessionDiv = document.createElement('div');
    sessionDiv.setAttribute('id', 'sessionDiv');
    sessionDiv.style.position = 'fixed';
    sessionDiv.style.bottom = '20px';
    sessionDiv.style.right = '20px';
    sessionDiv.style.padding = '10px';
    sessionDiv.style.backgroundColor = '#fff';
    sessionDiv.style.border = '2px solid #000';
    sessionDiv.style.zIndex = '9999';
    sessionDiv.innerHTML = `
        <div>Current Session:</div>
        <div id="currentSessionInfo">Loading...</div>
        <button id="closeButton">Close</button>
    `;
    document.body.appendChild(sessionDiv);

    // Function to update session information
    function updateSessionInfo(sessionData) {
        var sessionInfo = 'WPM: ' + sessionData.WPM + ' | Accuracy: ' + sessionData.Accuracy + ' | Races Completed: ' + sessionData.RacesCompleted;
        document.getElementById('currentSessionInfo').innerText = sessionInfo;
    }

    // Function to fetch user's session data from the Nitro Type page
    function fetchSessionData() {
        var statsContainer = document.querySelector('.nt-stats-metric-session-races').parentNode;
        if (statsContainer) {
            var sessionData = {
                WPM: statsContainer.querySelector('.nt-stats-metric-session-wpm').innerText.trim(),
                Accuracy: statsContainer.querySelector('.nt-stats-metric-session-accuracy').innerText.trim(),
                RacesCompleted: statsContainer.querySelector('.nt-stats-metric-session-races').innerText.trim()
            };
            updateSessionInfo(sessionData);
        } else {
            setTimeout(fetchSessionData, 1000); // Retry after 1 second if stats container is not found
        }
    }

    // Update session info initially
    fetchSessionData();

    // Close button event listener
    document.getElementById('closeButton').addEventListener('click', function() {
        sessionDiv.style.display = 'none';
    });

    // Refresh handler
    window.addEventListener('beforeunload', function() {
        sessionStorage.setItem('sessionDivDisplay', sessionDiv.style.display);
    });

    window.addEventListener('load', function() {
        var displaySetting = sessionStorage.getItem('sessionDivDisplay');
        if (displaySetting !== 'none') {
            sessionDiv.style.display = displaySetting;
        }
    });
})();