Display current session information on Nitro Type pages
当前为
// ==UserScript==
// @name Nitro Type Current Session Display
// @version 0.3
// @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 fetch user's session data from Nitro Type stats page
function fetchSessionData() {
GM_xmlhttpRequest({
method: 'GET',
url: 'https://www.nitrotype.com/stats',
onload: function(response) {
// Parse the HTML response to extract session data
var parser = new DOMParser();
var htmlDoc = parser.parseFromString(response.responseText, 'text/html');
var sessionDataElement = htmlDoc.querySelector('.stats-list');
// Extract session data
var sessionData = {};
sessionDataElement.querySelectorAll('li').forEach(function(item) {
var key = item.querySelector('div').innerText.trim().replace(/:/g, '');
var value = item.querySelector('span').innerText.trim();
sessionData[key] = value;
});
// Update session info with fetched data
updateSessionInfo(sessionData);
}
});
}
// Function to update session information
function updateSessionInfo(sessionData) {
var sessionInfo = 'WPM: ' + sessionData['Words per minute'] + ' | Accuracy: ' + sessionData['Accuracy'] + ' | Races Completed: ' + sessionData['Races Completed'];
document.getElementById('currentSessionInfo').innerText = sessionInfo;
}
// 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;
}
});
})();