Elo tracker

Adds an elo tracker to the GeoGuessr website

  1. // ==UserScript==
  2. // @name Elo tracker
  3. // @version 0.4.1
  4. // @description Adds an elo tracker to the GeoGuessr website
  5. // @match https://www.geoguessr.com/*
  6. // @run-at document-start
  7. // @author eru
  8. // @license MIT
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=geoguessr.com
  10. // @grant none
  11. // @namespace https://greasyfork.org/users/1348455
  12. // ==/UserScript==
  13.  
  14. /* jshint esversion: 8 */
  15.  
  16. const API_URL = 'https://ggstats.eu';
  17.  
  18. let nick = null;
  19. let hexId = null;
  20. let pinUrl = null;
  21. let level = null;
  22. let rating = null;
  23. let moveRating = null;
  24. let noMoveRating = null;
  25. let nmpzRating = null;
  26.  
  27. function updateElo(data) {
  28. fetch(API_URL+'/add-elo', {
  29. method: 'POST',
  30. headers: {
  31. 'Content-Type': 'application/json'
  32. },
  33. body: JSON.stringify(data)
  34. }).then(response => response.json()).then(data => console.log('Success:', data)).catch((error) => console.error('Error:', error));
  35. }
  36.  
  37. (function() {
  38. 'use strict';
  39.  
  40. function startWatching() {
  41.  
  42. let titleObserver = new MutationObserver(() => {
  43. if (document.title === "Ongoing duel - GeoGuessr") {
  44. fetch('https://www.geoguessr.com/api/v3/profiles')
  45. .then(response => response.json())
  46. .then(data => {
  47. nick = data.user.nick;
  48. hexId = data.user.id;
  49. pinUrl = data.user.pin.url;
  50. level = parseInt(data.user.br.level);
  51. fetch('https://www.geoguessr.com/api/v4/ranked-system/progress/'+hexId)
  52. .then(response => response.json())
  53. .then(fata => {
  54. rating = parseInt(fata.rating);
  55. moveRating = parseInt(fata.gameModeRatings.standardDuels);
  56. noMoveRating = parseInt(fata.gameModeRatings.noMoveDuels);
  57. nmpzRating = parseInt(fata.gameModeRatings.nmpzDuels);
  58. })
  59. .catch((error) => console.error('Error:', error));
  60. })
  61. .catch((error) => console.error('Error:', error));
  62. titleObserver.disconnect();
  63.  
  64.  
  65. let bodyObserver = new MutationObserver(() => {
  66. let targetElement = document.querySelector('div[class*="status-box_gameResult__"]');
  67. if (targetElement) {
  68. fetch('https://www.geoguessr.com/api/v4/ranked-system/progress/'+hexId)
  69. .then(response => response.json())
  70. .then(fata => {
  71. let newRating = parseInt(fata.rating);
  72. const data = {
  73. name: nick,
  74. playerHexId: hexId,
  75. elo: newRating,
  76. pinUrl: pinUrl,
  77. level: level,
  78. mode: null,
  79. modeElo: null
  80. };
  81. let newMoveRating = parseInt(fata.gameModeRatings.standardDuels);
  82. let newNoMoveRating = parseInt(fata.gameModeRatings.noMoveDuels);
  83. let newNmpzRating = parseInt(fata.gameModeRatings.nmpzDuels);
  84. if ((!isNaN(newMoveRating)) && (newMoveRating != moveRating)) {
  85. data.mode = 'move';
  86. data.modeElo = newMoveRating;
  87. }
  88. else if ((!isNaN(newNoMoveRating)) && (newNoMoveRating != noMoveRating)) {
  89. data.mode = 'nm';
  90. data.modeElo = newNoMoveRating;
  91. }
  92. else if ((!isNaN(newNmpzRating)) && (newNmpzRating != nmpzRating)) {
  93. data.mode = 'nmpz';
  94. data.modeElo = newNmpzRating;
  95. }
  96. console.log(data);
  97. updateElo(data);
  98. })
  99. .catch((error) => console.error('Error:', error));
  100. bodyObserver.disconnect();
  101. startWatching();
  102. }
  103. });
  104.  
  105. bodyObserver.observe(document.body, { childList: true, subtree: true });
  106. }
  107. });
  108.  
  109. titleObserver.observe(document.querySelector('title'), { childList: true });
  110. }
  111.  
  112.  
  113. startWatching();
  114. })();