Geoguessr Location Resolver (Works in all modes)

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

当前为 2024-04-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Geoguessr Location Resolver (Works in all modes)
  3. // @namespace http://tampermonkey.net/
  4. // @version 12.4
  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. let globalPanoID = undefined
  25.  
  26. // Below, I intercept the API call to Google Street view and view the result before it reaches the client.
  27. // Then I simply do some regex over the response string to find the coordinates, which Google gave to us in the response data
  28. // I then update a global variable above, with the correct coordinates, each time we receive a response from Google.
  29.  
  30. var originalOpen = XMLHttpRequest.prototype.open;
  31. XMLHttpRequest.prototype.open = function(method, url) {
  32. // Geoguessr now calls the Google Maps API multiple times each round, with subsequent requests overwriting
  33. // the saved coordinates. Calls to this exact API path seems to be legitimate for now. A better solution than panoID currently?
  34. // Needs testing.
  35. if (method.toUpperCase() === 'POST' &&
  36. (url.startsWith('https://maps.googleapis.com/$rpc/google.internal.maps.mapsjs.v1.MapsJsInternalService/GetMetadata') ||
  37. url.startsWith('https://maps.googleapis.com/$rpc/google.internal.maps.mapsjs.v1.MapsJsInternalService/SingleImageSearch'))) {
  38.  
  39. this.addEventListener('load', function () {
  40. let interceptedResult = this.responseText
  41. const pattern = /-?\d+\.\d+,-?\d+\.\d+/g;
  42. let match = interceptedResult.match(pattern)[0];
  43. let split = match.split(",")
  44.  
  45. let lat = Number.parseFloat(split[0])
  46. let lng = Number.parseFloat(split[1])
  47.  
  48.  
  49. globalCoordinates.lat = lat
  50. globalCoordinates.lng = lng
  51. });
  52. }
  53. // Call the original open function
  54. return originalOpen.apply(this, arguments);
  55. };
  56.  
  57.  
  58. // ====================================Placing Marker====================================
  59.  
  60. function placeMarker(safeMode){
  61. let {lat,lng} = globalCoordinates
  62.  
  63. if (safeMode) { // applying random values to received coordinates.
  64. const sway = [Math.random() > 0.5,Math.random() > 0.5]
  65. const multiplier = Math.random() * 4
  66. const horizontalAmount = Math.random() * multiplier
  67. const verticalAmount = Math.random() * multiplier
  68. sway[0] ? lat += verticalAmount : lat -= verticalAmount
  69. sway[1] ? lng += horizontalAmount : lat -= horizontalAmount
  70. }
  71.  
  72. // Okay well played Geoguessr u got me there for a minute, but below should work.
  73. // Below is the only intentionally complicated part of the code - it won't be simplified or explained for good reason.
  74. // let element = document.getElementsByClassName("guess-map_canvas__JAHHT")[0]
  75. let element = document.querySelectorAll('[class^="guess-map_canvas__"]')[0]
  76. if(!element){
  77. placeMarkerStreaks()
  78. return
  79. }
  80. const keys = Object.keys(element)
  81. const key = keys.find(key => key.startsWith("__reactFiber$"))
  82. const props = element[key]
  83. const x = props.return.return.memoizedProps.map.__e3_.click
  84. const y = Object.keys(x)[0]
  85.  
  86. const z = {
  87. latLng:{
  88. lat: () => lat,
  89. lng: () => lng,
  90. }
  91. }
  92.  
  93. const xy = x[y]
  94. const a = Object.keys(x[y])
  95.  
  96. for(let i = 0; i < a.length ;i++){
  97. let q = a[i]
  98. if (typeof xy[q] === "function"){
  99. xy[q](z)
  100. }
  101. }
  102. }
  103.  
  104. // similar idea as above, but with special considerations for the streaks modes.
  105. // again - will not be explained.
  106. function placeMarkerStreaks(){
  107. let {lat,lng} = globalCoordinates
  108. let element = document.getElementsByClassName("region-map_mapCanvas__R95Ki")[0]
  109. if(!element){
  110. return
  111. }
  112. const keys = Object.keys(element)
  113. const key = keys.find(key => key.startsWith("__reactFiber$"))
  114. const props = element[key]
  115. const x = props.return.return.memoizedProps.map.__e3_.click
  116. const y = Object.keys(x)
  117. const w = "(e.latLng.lat(),e.latLng.lng())}"
  118. const v = {
  119. latLng:{
  120. lat: () => lat,
  121. lng: () => lng,
  122. }
  123. }
  124. for(let i = 0; i < y.length; i++){
  125. const curr = Object.keys(x[y[i]])
  126. let func = curr.find(l => typeof x[y[i]][l] === "function")
  127. let prop = x[y[i]][func]
  128. if(prop && prop.toString().slice(5) === w){
  129. prop(v)
  130. }
  131. }
  132. }
  133.  
  134. // ====================================Open In Google Maps====================================
  135.  
  136. function mapsFromCoords() { // opens new Google Maps location using coords.
  137.  
  138. const {lat,lng} = globalCoordinates
  139. if (!lat || !lng) {
  140. return;
  141. }
  142.  
  143. if (nativeOpen) {
  144. const nativeOpenCodeIndex = nativeOpen.toString().indexOf('native code')
  145.  
  146. // Reject any attempt to call an overridden window.open, or fail.
  147. // 19 is for chromium-based browsers; 23 is for firefox-based browsers.
  148. if (nativeOpenCodeIndex === 19 || nativeOpenCodeIndex === 23) {
  149. nativeOpen(`https://maps.google.com/?output=embed&q=${lat},${lng}&ll=${lat},${lng}&z=5`);
  150. }
  151. }
  152. }
  153.  
  154. // ====================================Controls,setup, etc.====================================
  155.  
  156.  
  157. let onKeyDown = (e) => {
  158. if (e.keyCode === 49) {
  159. e.stopImmediatePropagation(); // tries to prevent the key from being hijacked by geoguessr
  160. placeMarker(true)
  161. }
  162. if (e.keyCode === 50) {
  163. e.stopImmediatePropagation();
  164. placeMarker(false)
  165. }
  166. if (e.keyCode === 51) {
  167. e.stopImmediatePropagation();
  168. mapsFromCoords(false)
  169. }
  170. }
  171.  
  172. document.addEventListener("keydown", onKeyDown);