Klavia Race Logger

Logs Klavia Races

بۇ قوليازمىنى بىۋاسىتە قاچىلاشقا بولمايدۇ. بۇ باشقا قوليازمىلارنىڭ ئىشلىتىشى ئۈچۈن تەمىنلەنگەن ئامبار بولۇپ، ئىشلىتىش ئۈچۈن مېتا كۆرسەتمىسىگە قىستۇرىدىغان كود: // @require https://update.greatest.deepsurf.us/scripts/532751/1570580/Klavia%20Race%20Logger.js

  1. // ==UserScript==
  2. // @name Klavia Race Logger
  3. // @version 2024-03-30
  4. // @namespace https://greatest.deepsurf.us/users/1331131-tensorflow-dvorak
  5. // @description Logs Klavia Races
  6. // @match *://*.ntcomps.com/*
  7. // @grant none
  8. // @run-at document-start
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. const script = document.createElement("script");
  14. script.textContent = `
  15. (function () {
  16. const STORAGE_KEY = "klaviaRaceHistory";
  17. const seenRaceIDs = new Set();
  18.  
  19. const estimatePoints = (wpm, accuracy) => Math.round(Math.pow(wpm, 1) * Math.pow(accuracy, 2.5) * 0.000027);
  20.  
  21. function loadRaceHistory() {
  22. try {
  23. return JSON.parse(localStorage.getItem(STORAGE_KEY)) || [];
  24. } catch {
  25. return [];
  26. }
  27. }
  28.  
  29. function saveRaceHistory(history) {
  30. localStorage.setItem(STORAGE_KEY, JSON.stringify(history));
  31. }
  32.  
  33. function attachRaceLogger(ws) {
  34. ws.addEventListener("message", (event) => {
  35. let parsed;
  36. try {
  37. parsed = JSON.parse(event.data);
  38. } catch {
  39. return;
  40. }
  41.  
  42. const identifier = parsed.identifier ? JSON.parse(parsed.identifier) : {};
  43. const msg = parsed.message;
  44.  
  45. if (
  46. identifier.channel === "RaceChannel" &&
  47. msg?.message === "update_race_results" &&
  48. msg?.textCompleted === true &&
  49. msg?.raceId &&
  50. !seenRaceIDs.has(msg.raceId)
  51. ) {
  52. seenRaceIDs.add(msg.raceId);
  53.  
  54. const raceData = {
  55. raceId: msg.raceId,
  56. points: estimatePoints(msg.wpm, parseFloat(msg.accuracy)),
  57. wpm: msg.wpm,
  58. accuracy: parseFloat(msg.accuracy),
  59. raceSeconds: msg.raceSeconds,
  60. textSeconds: msg.textSeconds,
  61. boostBonus: msg.boostBonus,
  62. timestamp: new Date().toISOString(),
  63. };
  64.  
  65. const history = loadRaceHistory();
  66. history.unshift(raceData);
  67. saveRaceHistory(history);
  68. }
  69. });
  70. }
  71.  
  72. const originalWS = window.WebSocket;
  73. window.WebSocket = new Proxy(originalWS, {
  74. construct(target, args) {
  75. const ws = new target(...args);
  76. attachRaceLogger(ws);
  77. return ws;
  78. }
  79. });
  80. })();
  81. `;
  82. document.documentElement.appendChild(script);
  83. })();