GeoGuessr Bigger Map on Map-Maker

Enables the user to have a bigger map when using the map-maker. It also hides top bar and sidebar.

当前为 2022-01-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GeoGuessr Bigger Map on Map-Maker
  3. // @namespace MrMike/GeoGuessr/GeoGuessrBiggerMapOnMapMaker
  4. // @version 0.6.0
  5. // @description Enables the user to have a bigger map when using the map-maker. It also hides top bar and sidebar.
  6. // @author MrAmericanMike
  7. // @include /^(https?)?(\:)?(\/\/)?([^\/]*\.)?geoguessr\.com($|\/.*)/
  8. // @grant none
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. "use strict";
  14.  
  15. // Enable this if you want the delete key to delete the current location not having to go click the delete button
  16. // set the value either true or false
  17. const ENABLE_DELETE_KEY = true;
  18. const ENABLE_LEAVE_PAGE_PREVENTION = true;
  19.  
  20. if (ENABLE_LEAVE_PAGE_PREVENTION) {
  21. window.addEventListener("beforeunload", (event) => {
  22. if (event.path[0].location.pathname == "/map-maker") {
  23. event.preventDefault();
  24. return event.returnValue = "Are you sure you want to exit?";
  25. }
  26. });
  27. }
  28.  
  29. function addGlobalStyle(css) {
  30. var head, style;
  31. head = document.getElementsByTagName("head")[0];
  32. if (!head) { return; }
  33. style = document.createElement("style");
  34. style.innerHTML = css.replace(/;/g, " !important;");
  35. head.appendChild(style);
  36. }
  37.  
  38. function doStyles() {
  39. addGlobalStyle(`
  40. .container__content {
  41. max-width: 98%;
  42. }
  43. .container--large {
  44. --width: 100rem;
  45. }
  46. .container--small {
  47. --width: 90rem;
  48. }
  49. .classic_layout__SWwJr {
  50. --layout-header-height: 0rem;
  51. }
  52. .classic_header__g_G4W, .title{
  53. display: none;
  54. }
  55. .classic_main__JenaD{
  56. margin: 0px;
  57. padding: 0px;
  58. }
  59. .classic_hasSubmenu__LfnDs {
  60. grid-template-columns: 0 1fr;
  61. }
  62. aside {
  63. display: none;
  64. }
  65. .streetview-panel {
  66. height: 100%;
  67. max-height: 100%;
  68. width: 50vw;
  69. }
  70. .map-maker-map__search {
  71. border: none;
  72. box-shadow: var(--shadow-1);
  73. font-size: var(--font-size-14);
  74. margin: 1rem;
  75. max-width: 75%;
  76. width: 50rem;
  77. }
  78. `);
  79. }
  80.  
  81. function resetStyles() {
  82. addGlobalStyle(`
  83. .container--large {
  84. --width: 87.5rem;
  85. }
  86. .container--small {
  87. --width: 40rem;
  88. }
  89. .classic_layout__SWwJr {
  90. --layout-header-height: 5rem;
  91. }
  92. .container__content {
  93. margin: 0 auto;
  94. max-width: var(--width);
  95. }
  96. aside {
  97. display: block;
  98. }
  99. `);
  100. }
  101.  
  102. function keyDown(event) {
  103. if (event.key == "Delete") {
  104. let buttons = document.getElementsByClassName("button--danger");
  105. for (let x = 0; x < buttons.length; x++) {
  106. if (buttons[x].textContent == "Delete") {
  107. buttons[x].click();
  108. }
  109. }
  110. }
  111. }
  112.  
  113. // LISTEN FOR PAGE CHANGES
  114. let currentTab = "";
  115. let oldTab = "";
  116.  
  117. window.addEventListener("click", (event) => {
  118. for (let x = 250; x < 2000; x += 250) {
  119. setTimeout(() => {
  120. lookForURLChange(event);
  121. }, x);
  122. }
  123. });
  124.  
  125. function lookForURLChange(event) {
  126. if (event.explicitOriginalTarget) {
  127. if (event.explicitOriginalTarget.baseURI) {
  128. currentTab = event.explicitOriginalTarget.baseURI;
  129. }
  130. }
  131. if (event.path) {
  132. event.path.forEach((element) => {
  133. if (element.hasOwnProperty("URL") && element.hasOwnProperty("location")) {
  134. currentTab = element.location.pathname;
  135. }
  136. });
  137. }
  138.  
  139. if (oldTab != currentTab) {
  140. oldTab = currentTab;
  141. if (currentTab.includes("map-maker")) {
  142. setTimeout(doStyles, 0);
  143. if (ENABLE_DELETE_KEY) {
  144. document.addEventListener("keydown", keyDown, true);
  145. }
  146.  
  147. }
  148. else {
  149. setTimeout(resetStyles, 0);
  150. if (ENABLE_DELETE_KEY) {
  151. document.removeEventListener("keydown", keyDown, true);
  152. }
  153. }
  154. }
  155. }
  156.  
  157. if (window.location.pathname.includes("map-maker")) {
  158. setTimeout(doStyles, 5);
  159. if (ENABLE_DELETE_KEY) {
  160. document.addEventListener("keydown", keyDown, true);
  161. }
  162. }
  163.  
  164. })();