Geoguessr Location Resolver (Works in all modes)

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

当前为 2024-01-11 提交的版本,查看 最新版本

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