Skip to content

Instantly share code, notes, and snippets.

@redex557
Created February 18, 2021 11:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redex557/d6c1a481de7e2bc7c33d0f71690f12e6 to your computer and use it in GitHub Desktop.
Save redex557/d6c1a481de7e2bc7c33d0f71690f12e6 to your computer and use it in GitHub Desktop.
Geoguessr Battle Royale Bot
// ==UserScript==
// @name Geoguessr Bot
// @version 1.0.0
// @description level up your geoguessr battle royale account
// @author Maxxx
// @require https://cdn.jsdelivr.net/gh/bigdatacloudapi/js-reverse-geocode-client@latest/bigdatacloud_reverse_geocode.min.js
// @match https://www.geoguessr.com/*
// @grant GM_xmlhttpRequest
// ==/UserScript==
function getTargetUrl() {
const raw = document.querySelectorAll("#__NEXT_DATA__")[0].text;
const json = JSON.parse(raw);
const rounds = json.props.pageProps.game.rounds;
console.log(rounds);
const currentRound = rounds[rounds.length - 1];
const targetUrl = "https://google.com/maps/place/" + currentRound.lat + "," + currentRound.lng;
return targetUrl;
}
function getLat(d) {
const json = JSON.parse(d);
const rounds = json.rounds;
const currentRound = rounds[rounds.length - 1];
return currentRound.lat;
}
function getLng(d) {
const json = JSON.parse(d);
const rounds = json.rounds;
const currentRound = rounds[rounds.length - 1];
return currentRound.lng;
}
function getRound(d) {
const json = JSON.parse(d);
const round = json.currentRoundNumber;
return round;
}
function getToken() {
const raw = document.querySelectorAll("#__NEXT_DATA__")[0].text;
const json = JSON.parse(raw);
const token = json.query.token;
return token;
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
(function() {
'use strict';
var reverseGeocoder=new BDCReverseGeocode();
var roundn = 0;
var guessr = function () {
let done = Array.from(document.getElementsByClassName("popup-view__header")).find(e => e.innerText.includes('qualified'));
if (done){
console.log("done here");
}
if (!done){
function $(d) { return document.getElementById(d); }
roundn += 1;
GM_xmlhttpRequest({
method: "post",
url: "https://game-server.geoguessr.com/api/battle-royale/"+getToken()+"/guess",
headers: { "Content-type" : "application/json" },
data: "{\"countryCode\":\"in\",\"roundNumber\":"+roundn+"}",
onload: function(e) { //console.log(e)
console.log("Send india guess for round "+getRound(e.responseText));
/* Get the administrative location information using a set of known coordinates */
reverseGeocoder.getClientLocation({
latitude: getLat(e.responseText),
longitude: getLng(e.responseText),
},async function(result) {
console.log(result.countryCode);
await sleep(3000);
GM_xmlhttpRequest({
method: "post",
url: "https://game-server.geoguessr.com/api/battle-royale/"+getToken()+"/guess",
headers: { "Content-type" : "application/json" },
data: "{\"countryCode\":\""+result.countryCode.toLowerCase()+"\",\"roundNumber\":"+getRound(e.responseText)+"}",
onload: function(f){ console.log("Send guess for round "+getRound(e.responseText)+" : "+result.countryCode.toLowerCase());
roundn = getRound(e.responseText);
}
});
});
}
});}
};
var restarter = function () {
let but = Array.from(document.getElementsByClassName("button button--medium button--ghost")).find(e => e.textContent === 'Play again');
if(but){
but.click();
}
};
window.setInterval(guessr, 10000);
window.setInterval(restarter, 30000);
})();
@redex557
Copy link
Author

Use with Tempermonkey/Greasemonkey extension for your favorite browser!

@MicrowavedBunny
Copy link

Thanks! I cleaned it up

@throwaway12334
Copy link

How do I use it?

@MicrowavedBunny
Copy link

How do I use it?

U need to use tampermonkey extension with chrome. install the script to the extension using the tampermonkey website. activate the script using the extension icon. I have what should have honestly been a fork of this on my Github that I know works because I couldn't get this one to work. Entirely up to you though if you want to use mine. It works the same way just cleaned it best I could.

@throwaway12334
Copy link

throwaway12334 commented Jul 30, 2021

How do I use it?

U need to use tampermonkey extension with chrome. install the script to the extension using the tampermonkey website. activate the script using the extension icon. I have what should have honestly been a fork of this on my Github that I know works because I couldn't get this one to work. Entirely up to you though if you want to use mine. It works the same way just cleaned it best I could.

Alright, I'll try yours out!

@MicrowavedBunny
Copy link

MicrowavedBunny commented Jul 30, 2021

@throwaway12334 just so you know with mine you have to refresh at the start of a new game and press alt+shift+f....... or g I forget, haha. Sometimes you have to wait a second for it to work. There is also a potential you get shadowbanned from the API it uses (YOU WILL NOT GET BANNED FROM GEOGUESSER) using a VPN to change IPs will fix any issues there.... If you get the alert box and it says "County: undefined" the API banned you and you need to change IPs. This has something to do with post requests I think. Also, tempermonkey will ask you to allow the script to use get/post requests on the site (geoguessr) allow it always and for all subdomains of geoguessr or it wont work

@throwaway12334
Copy link

throwaway12334 commented Jul 31, 2021

@MicrowavedBunny @throwaway12334 just so you know with mine you have to refresh at the start of a new game and press alt+shift+f....... or g I forget, haha. Sometimes you have to wait a second for it to work. There is also a potential you get shadowbanned from the API it uses (YOU WILL NOT GET BANNED FROM GEOGUESSER) using a VPN to change IPs will fix any issues there.... If you get the alert box and it says "County: undefined" the API banned you and you need to change IPs. This has something to do with post requests I think. Also, tempermonkey will ask you to allow the script to use get/post requests on the site (geoguessr) allow it always and for all subdomains of geoguessr or it wont work

Hey I've been using the distance one and doing as you say and keeps guessing in sydney - any reason why?

@MicrowavedBunny
Copy link

@MicrowavedBunny @throwaway12334 just so you know with mine you have to refresh at the start of a new game and press alt+shift+f....... or g I forget, haha. Sometimes you have to wait a second for it to work. There is also a potential you get shadowbanned from the API it uses (YOU WILL NOT GET BANNED FROM GEOGUESSER) using a VPN to change IPs will fix any issues there.... If you get the alert box and it says "County: undefined" the API banned you and you need to change IPs. This has something to do with post requests I think. Also, tempermonkey will ask you to allow the script to use get/post requests on the site (geoguessr) allow it always and for all subdomains of geoguessr or it wont work

Hey I've been using the distance one and doing as you say and keeps guessing in sydney - any reason why?

only reason thats ever happened to me was it just got stuck and refreshing and waiting a second would fix it. Ive won soooooooo many game with that thing. There are a couple of key binds for different functions in that one. One is like display where one is guess for you and another is open good maps.

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