Geoguessr Location Resolver (Works in all except Streak modes)

Features: Automatically score 5000 Points | Score randomly between 4500 and 5000 points | Open in Google Maps

当前为 2023-10-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Geoguessr Location Resolver (Works in all except Streak modes)
  3. // @namespace http://tampermonkey.net/
  4. // @version 11.0
  5. // @description Features: Automatically score 5000 Points | Score randomly between 4500 and 5000 points | Open in Google Maps
  6. // @author 0x978
  7. // @match https://www.geoguessr.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=geoguessr.com
  9. // @grant GM_webRequest
  10. // ==/UserScript==
  11.  
  12.  
  13. // =================================================================================================================
  14. // 'An idiot admires complexity, a genius admires simplicity'
  15. // Learn how I made this script: https://github.com/0x978/GeoGuessr_Resolver/blob/master/howIMadeTheScript.md
  16. // Contribute things you think will be cool once you learn: https://github.com/0x978/GeoGuessr_Resolver/pulls
  17. // ================================================================================================================
  18.  
  19. let globalCoordinates = { // keep this stored globally, and we'll keep updating it for each API call.
  20. lat: 0,
  21. lng: 0
  22. }
  23.  
  24. // ==================================== ANTI-ANTI-cheat stuff ====================================
  25. window.alert = function (message) { // Stop any attempt to overwrite alert, or fail silently and send no alert at all.
  26. if(nativeAlert){
  27. nativeAlert(message)
  28. }
  29. };
  30. GM_webRequest([
  31. { selector: 'https://www.geoguessr.com/api/v4/trails', action: 'cancel' },
  32. { selector: 'https://www.geoguessr.com/api/v4/bdd406e4-c426-4d04-85b3-230f6fceef28', action: 'cancel' },
  33. ]);
  34. // ==================================== Coordinate Interception ====================================
  35.  
  36. // Below, I intercept the API call to Google Street view and view the result before it reaches the client.
  37. // Then I simply do some regex over the response string to find the coordinates, which Google gave to us in the response data
  38. // I then update a global variable above, with the correct coordinates, each time we receive a response from Google.
  39. // This needs further testing - but initial tests look promising
  40. var originalOpen = XMLHttpRequest.prototype.open;
  41. XMLHttpRequest.prototype.open = function(method, url) {
  42. if (url.startsWith('https://maps.googleapis.com')) {
  43.  
  44. this.addEventListener('load', function () {
  45. let interceptedResult = this.responseText
  46. const pattern = /-?\d+\.\d+,-?\d+\.\d+/g;
  47. let match = interceptedResult.match(pattern)[0];
  48. let split = match.split(",")
  49.  
  50. let lat = Number.parseFloat(split[0])
  51. let lng = Number.parseFloat(split[1])
  52. globalCoordinates.lat = lat
  53. globalCoordinates.lng = lng
  54. });
  55. }
  56.  
  57. // Call the original open function
  58. return originalOpen.apply(this, arguments);
  59. };
  60.  
  61.  
  62. // ====================================Placing Marker====================================
  63.  
  64. function placeMarker(safeMode){
  65. const {lat,lng} = globalCoordinates
  66.  
  67. // Okay well played Geoguessr u got me there for a minute, but below should work.
  68. // Below is the only intentionally complicated part of the code - it won't be simplified or explained for good reason.
  69. const element = document.getElementsByClassName("guess-map_canvas__cvpqv")[0]
  70. const keys = Object.keys(element)
  71. const key = keys.find(key => key.startsWith("__reactFiber$"))
  72. const props = element[key]
  73. const x = props.return.return.memoizedProps.map.__e3_.click
  74. const y = Object.keys(x)[0]
  75.  
  76. const z = {
  77. latLng:{
  78. lat: () => lat,
  79. lng: () => lng,
  80. }
  81. }
  82. x[y].xe(z)
  83. }
  84.  
  85. // ====================================Open In Google Maps====================================
  86.  
  87. function mapsFromCoords() { // opens new Google Maps location using coords.
  88. const {lat,lng} = globalCoordinates
  89. if (!lat || !lng) {
  90. console.log("Failed to fetch coords for Google Maps")
  91. return;
  92. }
  93. window.open(`https://www.google.com/maps/place/${lat},${lng}`);
  94. }
  95.  
  96. // ====================================Controls,setup, etc.====================================
  97.  
  98. function setInnerText(){
  99. const text = `
  100. Geoguessr Resolver Loaded Successfully
  101.  
  102. IMPORTANT GEOGUESSR RESOLVER UPDATE INFORMATION:
  103. The script has been rewritten after a big update by the developers.
  104. Using the marker place functions are at your risk during the initial testing of this update
  105. Open in Google maps should be fine.
  106. `
  107. const logoWrapper = document.querySelector('.header_logoWrapper__WNmfy');
  108. const newHeading = document.createElement('h4');
  109. newHeading.innerText = text
  110.  
  111. if (logoWrapper) {
  112. // Remove all child elements of the selected div
  113. while (logoWrapper.firstChild) {
  114. logoWrapper.removeChild(logoWrapper.firstChild);
  115. }
  116. logoWrapper.appendChild(newHeading);
  117. }
  118. }
  119.  
  120. let onKeyDown = (e) => {
  121. if (e.keyCode === 49) {
  122. e.stopImmediatePropagation(); // tries to prevent the key from being hijacked by geoguessr
  123. placeMarker(true)
  124. }
  125. if (e.keyCode === 50) {
  126. e.stopImmediatePropagation();
  127. placeMarker(false)
  128. }
  129. if (e.keyCode === 51) {
  130. e.stopImmediatePropagation();
  131. mapsFromCoords(false)
  132. }
  133. }
  134. setInnerText()
  135. document.addEventListener("keydown", onKeyDown);
  136.