Skip to content

Instantly share code, notes, and snippets.

@tcortega
Last active December 19, 2022 19:03
Show Gist options
  • Save tcortega/7378d20dcfa7d15df780032ca2b78b3d to your computer and use it in GitHub Desktop.
Save tcortega/7378d20dcfa7d15df780032ca2b78b3d to your computer and use it in GitHub Desktop.
Geoguessr AIO Cheat (Greasemonkey / Tampermonkey)
// ==UserScript==
// @name Geoguessr AIO Cheat
// @namespace https://github.com/tcortega
// @version 1.0.1
// @description Press SHIFT + ALT + G and the location of your current geoguessr game will open in a new tab
// @author tcortega
// @homepage https://github.com/tcortega
// @downloadURL https://gist.github.com/tcortega/7378d20dcfa7d15df780032ca2b78b3d/raw/geoguessr-aio.user.js
// @updateURL https://gist.github.com/tcortega/7378d20dcfa7d15df780032ca2b78b3d/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 "DUELS":
case "TEAM-DUELS":
case "BATTLE-ROYALE": {
return url.replace("geoguessr.com", "game-server.geoguessr.com/api").replace("team-duels", "duels");
}
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 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 == "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();
}
};
})();
@volkmanS
Copy link

Doesnt work today in duels - in BR its work. WTF ?

@bombcheats
Copy link

Confirmed Patched for Duels ( location takes you to Alcatraz every time ). Still working in Battle Royale.

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