Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Country Streak Counter
- // @include /^(https?)?(\:)?(\/\/)?([^\/]*\.)?geoguessr\.com($|\/.*)/
- // @description Adds a Country Streak counter to GeoGuessr website
- // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
- // @grant GM_addStyle
- // ==/UserScript==
- if(sessionStorage.getItem("Streak") == null) {
- sessionStorage.setItem("Streak", 0);
- streak = 0;
- };
- let streak = parseInt(sessionStorage.getItem("Streak"), 10);
- function updateStreak(newVariable) {
- streak = newVariable;
- if(document.getElementById("country-streak") != null) {
- document.getElementById("country-streak").innerHTML = `<div id="country-streak"><font size="5"><h6>${streak}</h6></font></div>`;
- };
- if(document.getElementById("country-streak2") != null && document.getElementsByClassName("margin--bottom").length == 1) {
- document.getElementById("country-streak2").innerHTML = `<h2>Country Streak: ${streak}</h2><br>`;
- };
- if(document.getElementById("country-streak2") != null && document.getElementsByClassName("margin--bottom").length == 3) {
- document.getElementById("country-streak2").innerHTML = `<h2>Country Streak: ${streak}</h2>`;
- };
- };
- function addCounter(newDiv1) {
- if(document.getElementsByClassName("game-status").length == 3) {
- newDiv1 = document.createElement("div")
- newDiv1.className = 'game-status';
- document.getElementsByClassName("game-statuses")[0].appendChild(newDiv1);
- newDiv1.innerHTML = `<div class="game-status__heading">Streak</div><div id="country-streak"><font size="5"><h6>${streak}</h6></font></div>`;
- };
- };
- function addCounterOnRefresh() {
- setTimeout(function(){
- addCounter();
- },50);
- };
- function addCounter2() {
- addCounter();
- if(document.getElementsByClassName("game-status").length == 0) {
- setTimeout(function() {
- addCounter();
- }, 400);
- return;
- };
- };
- function addStreak(newDiv2) {
- setTimeout(function(){
- if(document.getElementById("country-streak2") == null && document.getElementsByClassName("margin--bottom").length == 1) {
- newDiv2 = document.createElement("div")
- document.getElementsByClassName("stack__item")[0].appendChild(newDiv2);
- newDiv2.innerHTML = `<div id="country-streak2" style="text-align:center"><h2>Country Streak: ${streak}</h2><br></div>`;
- };
- },300);
- setTimeout(function(){
- if(document.getElementById("country-streak2") == null && document.getElementsByClassName("margin--bottom").length == 1) {
- newDiv2 = document.createElement("div")
- document.getElementsByClassName("stack__item")[0].appendChild(newDiv2);
- newDiv2.innerHTML = `<div id="country-streak2" style="text-align:center"><h2>Country Streak: ${streak}</h2><br></div>`;
- };
- },500);
- setTimeout(function(){
- if(document.getElementById("country-streak2") == null && document.getElementsByClassName("margin--bottom").length == 3) {
- newDiv2 = document.createElement("div")
- document.getElementsByClassName("margin--bottom")[0].appendChild(newDiv2);
- newDiv2.innerHTML = `<div id="country-streak2" style="text-align:center"><h2>Country Streak: ${streak}</h2></div>`;
- };
- },200);
- setTimeout(function(){
- if(document.getElementById("country-streak2") == null && document.getElementsByClassName("margin--bottom").length == 3) {
- newDiv2 = document.createElement("div")
- document.getElementsByClassName("margin--bottom")[0].appendChild(newDiv2);
- newDiv2.innerHTML = `<div id="country-streak2" style="text-align:center"><h2>Country Streak: ${streak}</h2></div>`;
- };
- },400);
- };
- document.addEventListener('keypress', (e) => {
- switch (e.key) {
- case '1':
- updateStreak(streak + 1);
- sessionStorage.setItem("Streak", streak);
- break;
- case '2':
- updateStreak(streak - 1);
- sessionStorage.setItem("Streak", streak);
- break;
- case '0':
- updateStreak(0);
- sessionStorage.setItem("Streak", 0);
- break;
- };
- });
- document.addEventListener('click', addCounter2, false);
- document.addEventListener('click', addStreak, false);
- document.addEventListener('load', addCounterOnRefresh(), false);
Add Comment
Please, Sign In to add comment