Skip to content

Instantly share code, notes, and snippets.

@michele-grifa
Forked from tcortega/geoguessr-aio.user.js
Last active August 28, 2022 20:53
Show Gist options
  • Save michele-grifa/bc70e735905fec7d9d28df0e653dd45d to your computer and use it in GitHub Desktop.
Save michele-grifa/bc70e735905fec7d9d28df0e653dd45d to your computer and use it in GitHub Desktop.
Geoguessr AIO Cheat (Greasemonkey / Tampermonkey)
// ==UserScript==
// @name Geoguessr AIO Cheat
// @namespace https://github.com/michele-grifa
// @version 1.0.2
// @description Press SHIFT + ALT + G and the location of your current geoguessr game will open in a new tab
// @author michele-grifa
// @homepage https://github.com/michele-grifa
// @downloadURL https://gist.github.com/michele-grifa/bc70e735905fec7d9d28df0e653dd45d/raw/geoguessr-aio.user.js
// @updateURL https://gist.github.com/michele-grifa/bc70e735905fec7d9d28df0e653dd45d/raw/geoguessr-aio.user.js
// @match http*://*/*
// @grant none
// @run-at document-idle
// ==/UserScript==
function getCleanUrl() {
return window.location.href.replace("/reconnect", "").replace("?client=web", "");
}
function getJsonData() {
const rawData = document.querySelector("pre").innerText;
return JSON.parse(rawData);
}
function apiUrlToGameUrl() {
const apiUrl = getCleanUrl();
return apiUrl.replace("game-server.", "").replace("/api", "").replace("/v3", "").replace("");
}
function getGameMode(url) {
return url.split(".com/")[1].split("/")[0].toUpperCase();
}
function getApiUrl(url, gamemode) {
url = url.replace("www.", "");
switch (gamemode) {
case "QUIZ":
case "LIVE-CHALLENGE":
case "DUELS":
case "TEAM-DUELS":
case "BATTLE-ROYALE": {
return url.replace("geoguessr.com", "game-server.geoguessr.com/api").replace("team-duels", "duels").replace("quiz/play", "live-challenge");
}
case "COMPETITIVE-STREAK": {
return url.replace("geoguessr.com/competitive-streak", "game-server.geoguessr.com/api/competitive-streaks");
}
case "GAME": {
return url.replace("geoguessr.com/game", "geoguessr.com/api/v3/games");
}
}
}
function isApiPage() {
return getCleanUrl().includes("/api/");
}
function makeApiCall(apiUrl) {
window.open(apiUrl, "_blank");
}
function handleChallenge() {
const raw = document.querySelectorAll("#__NEXT_DATA__")[0].text;
const json = JSON.parse(raw);
const rounds = json.props.pageProps.game.rounds;
const { lat, lng } = rounds[rounds.length - 1];
openMaps({ lat, lng }, "_blank");
}
function handleKeyEvent() {
const url = getCleanUrl();
const gameMode = getGameMode(url);
if (gameMode == "CHALLENGE") return handleChallenge();
const apiUrl = getApiUrl(url, gameMode);
makeApiCall(apiUrl);
}
function formatDuelsResponse(jsonData) {
const rounds = jsonData.rounds.map((r) => ({ lat: r.panorama.lat, lng: r.panorama.lng }));
return { round: jsonData.currentRoundNumber, rounds };
}
function formatLiveChallengeResponse(jsonData) {
const rounds = jsonData.rounds.map((r) => ({ lat: r.question.panoramaQuestionPayload.panorama.lat, lng: r.question.panoramaQuestionPayload.panorama.lng }));
return { round: jsonData.currentRoundNumber, rounds };
}
function formatStreaksResponse(jsonData) {
const rounds = [jsonData.player.currentRound];
return { round: 1, rounds };
}
function formatBattleRoyaleResponse({ currentRoundNumber, rounds }) {
return { round: currentRoundNumber, rounds };
}
function formatGameResponse({ round, rounds }) {
return { round, rounds };
}
function formatResponse(gameMode) {
const jsonData = getJsonData();
if (gameMode == "LIVE-CHALLENGE" || gameMode == "QUIZ") return formatLiveChallengeResponse(jsonData);
if (gameMode == "DUELS"|| gameMode == "TEAM-DUELS") return formatDuelsResponse(jsonData);
if (gameMode == "COMPETITIVE-STREAKS") return formatStreaksResponse(jsonData);
if (gameMode == "BATTLE-ROYALE") return formatBattleRoyaleResponse(jsonData);
if (gameMode == "GAMES") return formatGameResponse(jsonData);
}
function getLocation(gameMode) {
const { round, rounds } = formatResponse(gameMode);
const currentRound = rounds[round - 1];
return { lat: currentRound.lat, lng: currentRound.lng };
}
function openMaps(location, target = "_self") {
const mapUrl = `https://google.com/maps/place/${location.lat},${location.lng}`;
window.open(mapUrl, target);
}
function handleApiPage() {
const gameUrl = apiUrlToGameUrl();
const gameMode = getGameMode(gameUrl);
const location = getLocation(gameMode);
openMaps(location);
}
(function () {
"use strict";
if (!getCleanUrl().includes("geoguessr.com")) return; // Just in case
if (isApiPage()) {
return handleApiPage();
}
// TO-DO: Refactor this so it does not have to figure out which game mode is being used each time the user issues the command (lazy to do rn).
document.onkeydown = (evt) => {
evt = evt || window.event;
if (evt.shiftKey && evt.altKey && evt.keyCode == 71) {
handleKeyEvent();
}
};
})();
@tcortega
Copy link

Nice job 😁

@michele-grifa
Copy link
Author

michele-grifa commented Apr 15, 2022

Nice job 😁

I'm working on a version that automatically guess the place based on the API data. Only for Educational Purposes πŸ˜‚

@tcortega
Copy link

Nice job 😁

I'm working on a version that automatically guess the place based on the API data. Only for Educational Purposes πŸ˜‚

It's quite easy to do that, just use take a look at the request that is sent whenever an user guess the location, and replicate it with js. Good Luck πŸ‘

@michele-grifa
Copy link
Author

Nice job 😁

I'm working on a version that automatically guess the place based on the API data. Only for Educational Purposes πŸ˜‚

It's quite easy to do that, just use take a look at the request that is sent whenever an user guess the location, and replicate it with js. Good Luck πŸ‘

Yes I know, i have already replicated the request for normal streaks, bypassing CORS. I want also to add a bit of randomess to the guess, so that sometimes try to guess some meter of distance.

@abckljqsf
Copy link

Hello, I have a small question. How can we make the new map page replace the old one?

@krzyst333q
Copy link

Great Job! Love u

@Xarond12
Copy link

hello, i'm looking for drawing location on map script. I had something like that but by mistake i removed it

@tcortega
Copy link

hello, i'm looking for drawing location on map script. I had something like that but by mistake i removed it

Stop asking in every gist that you find online and go try to make it yourself. All you have to do is make a request, get the coords and add a marker to the map instance using the google maps api. For lord's sake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment