xpzm3

Country Streak Counter

May 8th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Country Streak Counter
  3. // @include /^(https?)?(\:)?(\/\/)?([^\/]*\.)?geoguessr\.com($|\/.*)/
  4. // @description Adds a Country Streak counter to GeoGuessr website
  5. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  6. // @grant GM_addStyle
  7. // ==/UserScript==
  8.  
  9. if(sessionStorage.getItem("Streak") == null) {
  10. sessionStorage.setItem("Streak", 0);
  11. streak = 0;
  12. };
  13.  
  14. let streak = parseInt(sessionStorage.getItem("Streak"), 10);
  15.  
  16. function updateStreak(newVariable) {
  17. streak = newVariable;
  18. if(document.getElementById("country-streak") != null) {
  19. document.getElementById("country-streak").innerHTML = `<div id="country-streak"><font size="5"><h6>${streak}</h6></font></div>`;
  20. };
  21. if(document.getElementById("country-streak2") != null && document.getElementsByClassName("margin--bottom").length == 1) {
  22. document.getElementById("country-streak2").innerHTML = `<h2>Country Streak: ${streak}</h2><br>`;
  23. };
  24. if(document.getElementById("country-streak2") != null && document.getElementsByClassName("margin--bottom").length == 3) {
  25. document.getElementById("country-streak2").innerHTML = `<h2>Country Streak: ${streak}</h2>`;
  26. };
  27. };
  28.  
  29. function addCounter(newDiv1) {
  30. if(document.getElementsByClassName("game-status").length == 3) {
  31. newDiv1 = document.createElement("div")
  32. newDiv1.className = 'game-status';
  33. document.getElementsByClassName("game-statuses")[0].appendChild(newDiv1);
  34.  
  35. newDiv1.innerHTML = `<div class="game-status__heading">Streak</div><div id="country-streak"><font size="5"><h6>${streak}</h6></font></div>`;
  36. };
  37. };
  38.  
  39. function addCounterOnRefresh() {
  40. setTimeout(function(){
  41. addCounter();
  42. },50);
  43. };
  44.  
  45. function addCounter2() {
  46. addCounter();
  47. if(document.getElementsByClassName("game-status").length == 0) {
  48. setTimeout(function() {
  49. addCounter();
  50. }, 400);
  51. return;
  52. };
  53. };
  54.  
  55. function addStreak(newDiv2) {
  56. setTimeout(function(){
  57. if(document.getElementById("country-streak2") == null && document.getElementsByClassName("margin--bottom").length == 1) {
  58. newDiv2 = document.createElement("div")
  59. document.getElementsByClassName("stack__item")[0].appendChild(newDiv2);
  60. newDiv2.innerHTML = `<div id="country-streak2" style="text-align:center"><h2>Country Streak: ${streak}</h2><br></div>`;
  61. };
  62. },300);
  63. setTimeout(function(){
  64. if(document.getElementById("country-streak2") == null && document.getElementsByClassName("margin--bottom").length == 1) {
  65. newDiv2 = document.createElement("div")
  66. document.getElementsByClassName("stack__item")[0].appendChild(newDiv2);
  67. newDiv2.innerHTML = `<div id="country-streak2" style="text-align:center"><h2>Country Streak: ${streak}</h2><br></div>`;
  68. };
  69. },500);
  70. setTimeout(function(){
  71. if(document.getElementById("country-streak2") == null && document.getElementsByClassName("margin--bottom").length == 3) {
  72. newDiv2 = document.createElement("div")
  73. document.getElementsByClassName("margin--bottom")[0].appendChild(newDiv2);
  74. newDiv2.innerHTML = `<div id="country-streak2" style="text-align:center"><h2>Country Streak: ${streak}</h2></div>`;
  75. };
  76. },200);
  77. setTimeout(function(){
  78. if(document.getElementById("country-streak2") == null && document.getElementsByClassName("margin--bottom").length == 3) {
  79. newDiv2 = document.createElement("div")
  80. document.getElementsByClassName("margin--bottom")[0].appendChild(newDiv2);
  81. newDiv2.innerHTML = `<div id="country-streak2" style="text-align:center"><h2>Country Streak: ${streak}</h2></div>`;
  82. };
  83. },400);
  84. };
  85.  
  86. document.addEventListener('keypress', (e) => {
  87. switch (e.key) {
  88. case '1':
  89. updateStreak(streak + 1);
  90. sessionStorage.setItem("Streak", streak);
  91. break;
  92. case '2':
  93. updateStreak(streak - 1);
  94. sessionStorage.setItem("Streak", streak);
  95. break;
  96. case '0':
  97. updateStreak(0);
  98. sessionStorage.setItem("Streak", 0);
  99. break;
  100. };
  101. });
  102.  
  103. document.addEventListener('click', addCounter2, false);
  104. document.addEventListener('click', addStreak, false);
  105. document.addEventListener('load', addCounterOnRefresh(), false);
Add Comment
Please, Sign In to add comment