WPM Library for Nitro Type

Library that calculates WPM, accuracy, and errors allowed for Nitro Type races

이 스크립트는 직접 설치하는 용도가 아닙니다. 다른 스크립트에서 메타 지시문 // @require https://update.greatest.deepsurf.us/scripts/513772/1470274/WPM%20Library%20for%20Nitro%20Type.js을(를) 사용하여 포함하는 라이브러리입니다.

  1. // ==UserScript==
  2. // @name WPM Library for Nitro Type
  3. // @namespace https://greatest.deepsurf.us/users/1331131-tensorflow-dvorak
  4. // @version 2024-10-22
  5. // @description Library that calculates WPM, accuracy, and errors allowed for Nitro Type races
  6. // @author TensorFlow - Dvorak
  7. // @match *://*.nitrotype.com/race
  8. // @match *://*.nitrotype.com/race/*
  9. // @require https://update.greatest.deepsurf.us/scripts/501960/1418069/findReact.js
  10. // @license MIT
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. "use strict";
  16.  
  17. let startTime = null;
  18. let peakWPM = 0;
  19. let totalTypedCharacters = 0;
  20. let totalCorrectlyTypedCharacters = 0;
  21. let totalIncorrectTypedCharacters = 0;
  22. const trackedIncorrectLetters = new Set();
  23. let totalCharactersInRace = 0;
  24. let errorsAllowed = 0;
  25.  
  26. function calculateWPM(totalCharacters, timeInSeconds) {
  27. const wordsTyped = totalCharacters / 5;
  28. const WPM = (wordsTyped * 60) / timeInSeconds;
  29. return WPM;
  30. }
  31.  
  32. function calculateErrorsAllowed(totalCharacters) {
  33. return Math.floor(0.04 * totalCharacters);
  34. }
  35.  
  36. function getCorrectlyTypedCharacterCount() {
  37. const correctLetters = document.querySelectorAll(
  38. ".dash-letter.is-correct.is-typed"
  39. );
  40. return correctLetters.length;
  41. }
  42.  
  43. function detectMistakes() {
  44. const incorrectLetters = document.querySelectorAll(
  45. ".dash-letter.is-incorrect"
  46. );
  47. incorrectLetters.forEach((letter) => {
  48. if (!trackedIncorrectLetters.has(letter)) {
  49. totalIncorrectTypedCharacters += 1;
  50. trackedIncorrectLetters.add(letter);
  51. errorsAllowed = Math.max(0, errorsAllowed - 1);
  52. }
  53. });
  54. }
  55.  
  56. function getTotalTypedCharacterCount() {
  57. const typedLetters = document.querySelectorAll(".dash-letter.is-typed");
  58. return typedLetters.length;
  59. }
  60.  
  61. function getTotalCharacters() {
  62. const totalLetters = document.querySelectorAll(".dash-letter").length;
  63. return totalLetters;
  64. }
  65.  
  66. function calculateAccuracy(correctCharacters, incorrectCharacters) {
  67. const totalTyped = correctCharacters + incorrectCharacters;
  68. return (correctCharacters / totalTyped) * 100;
  69. }
  70.  
  71. function startTracking() {
  72. startTime = new Date();
  73. peakWPM = 0;
  74. totalTypedCharacters = 0;
  75. totalCorrectlyTypedCharacters = 0;
  76. totalIncorrectTypedCharacters = 0;
  77. trackedIncorrectLetters.clear();
  78.  
  79. totalCharactersInRace = getTotalCharacters();
  80. errorsAllowed = calculateErrorsAllowed(totalCharactersInRace);
  81. }
  82.  
  83. function updateTracking() {
  84. const currentTime = new Date();
  85. const elapsedTime = (currentTime - startTime) / 1000;
  86.  
  87. const correctlyTypedCharacters = getCorrectlyTypedCharacterCount();
  88. totalTypedCharacters = getTotalTypedCharacterCount();
  89. detectMistakes();
  90.  
  91. const wpm = calculateWPM(correctlyTypedCharacters, elapsedTime);
  92. const accuracy = calculateAccuracy(
  93. correctlyTypedCharacters,
  94. totalIncorrectTypedCharacters
  95. );
  96.  
  97. if (wpm > peakWPM) {
  98. peakWPM = wpm;
  99. }
  100.  
  101. return {
  102. wpm: Math.round(wpm),
  103. accuracy: accuracy.toFixed(2),
  104. errorsAllowed: errorsAllowed,
  105. };
  106. }
  107.  
  108. window.WPMLibrary = {
  109. start: startTracking,
  110. update: updateTracking,
  111. };
  112. })();