forked from 0x978/GeoGuessr_Resolver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResolver.js
More file actions
117 lines (91 loc) · 4.87 KB
/
Resolver.js
File metadata and controls
117 lines (91 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// ==UserScript==
// @name geoGuessr Resolver (dev)
// @namespace http://tampermonkey.net/
// @version 7.5
// @description Features: Automatically score 5000 Points | Score randomly between 4500 and 5000 points | Open in Google Maps
// @author 0x978
// @match https://www.geoguessr.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=geoguessr.com
// @grant none
// ==/UserScript==
alert(` Thanks for using geoGuessr Resolver by 0x978.
============================================
Please use the safer guess Option to avoid bans in competitive
============================================
Controls (UPDATED!):
'1': Place marker on a "safe" guess (4500 - 5000)
'2': Place marker on a "perfect" guess (5000)
'3': Get a description of the correct location.
'4': Open location in Google Maps (In a new tab)
----------------------------------------------------------`)
async function getAddress(lat,lon){
let response = await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lon}&format=json`)
return await response.json();
}
function displayLocationInfo() {
let coordinates = getCoordinates()
// api call with the lat lon to retrieve data.
getAddress(coordinates[0],coordinates[1]).then(data => {
console.log(data)
alert(`
Country: ${data.address.country}
County: ${data.address.county}
City: ${data.address.city}
Road: ${data.address.road}
State: ${data.address.state}
Postcode: ${data.address.postcode}
Village/Suburb: ${(data.address.village||data.address.suburb)}
Postal Address: ${data.display_name}
`) } );
}
function placeMarker(safeMode){
let [lat,lng] = getCoordinates()
if(document.getElementsByClassName("guess-map__canvas-container")[0] === undefined){ // if this is not defined, the user must be in a streaks game, streaks mode uses a different map and therefore is calculated in a different function
placeMarkerStreaksMode([lat,lng])
return;
}
if(safeMode){
lat += (Math.random() / 2);
lng += (Math.random() / 2);
}
let element = document.getElementsByClassName("guess-map__canvas-container")[0] // html element containing needed props.
let keys = Object.keys(element) // all keys
let key = keys.find(key => key.startsWith("__reactFiber$")) // the React key I need to access props
let placeMarker = element[key].return.memoizedProps.onMarkerLocationChanged // getting the function which will allow me to place a marker on the map
placeMarker({lat:lat,lng:lng}) // placing the marker on the map at the correct coordinates given by getCoordinates(). Must be passed as an Object.
}
function placeMarkerStreaksMode([lat,lng]){
let element = document.getElementsByClassName("region-map_map__7jxcD")[0] // this map is unique to streaks mode, however, is similar to that found in normal modes.
let keys = Object.keys(element)
let reactKey = keys.find(key => key.startsWith("__reactFiber$"))
let placeMarkerFunction = element[reactKey].return.memoizedProps.onRegionSelected // This map works by selecting regions, not exact coordinates on a map, which is handles by the "onRegionSelected" function.
// the onRegionSelected method of the streaks map doesn't accept an object containing coordinates like the other game-modes.
// Instead, it accepts the country's 2-digit IBAN country code.
// For now, I will pass the location coordinates into an API to retrieve the correct Country code, but I believe I can find a way without the API in the future.
// TODO: find a method without using an API since the API is never guaranteed.
getAddress(lat,lng).then(data => { // using API to retrieve the country code at the current coordinates.
let countryCode = data.address.country_code
placeMarkerFunction(countryCode) // passing the country code into the onRegionSelected method.
})
}
// detects game mode and return appropriate coordinates.
function getCoordinates(){
let x = document.getElementsByClassName("styles_root__3xbKq")[0]
let keys = Object.keys(x)
let key = keys.find(key => key.startsWith("__reactFiber$"))
let props = x[key]
let found = props.return.memoizedProps.panorama.position
return([found.lat(),found.lng()]) // lat and lng are functions returning the lat/lng values
}
function mapsFromCoords(){ // opens new Google Maps location using coords.
let [lat,lon] = getCoordinates()
if(!lat||!lon){return;}
window.open(`https://www.google.com/maps/place/${lat},${lon}`);
}
let onKeyDown = (e) => {
if(e.keyCode === 49){placeMarker(true)}
if(e.keyCode === 50){placeMarker(false)}
if(e.keyCode === 51){displayLocationInfo()}
if(e.keyCode === 52){mapsFromCoords()}
}
document.addEventListener("keydown", onKeyDown);