GeoGuessr Background Replacer

Replaces the background of the geoguessr pages with your own image

当前为 2023-05-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GeoGuessr Background Replacer
  3. // @description Replaces the background of the geoguessr pages with your own image
  4. // @version 1.3.2
  5. // @author Tyow#3742
  6. // @match *://*.geoguessr.com/*
  7. // @license MIT
  8. // @run-at document-start
  9. // @require https://unpkg.com/@popperjs/core@2.11.5/dist/umd/popper.min.js
  10. // @namespace https://greasyfork.org/users/1011193
  11. // @grant GM_addStyle
  12. // ==/UserScript==
  13.  
  14. //Add image links for the homePage in this list. If left blank, the default image will be shown
  15. const homePageImageList = [
  16. "https://cdn.wallpapersafari.com/6/80/9ZbpYo.jpg",
  17. "https://cdn.wallpapersafari.com/25/72/dtkc16.jpg",
  18. "https://i.imgur.com/l9K9IOq.jpg",
  19. ];
  20.  
  21. // Add image links for the rest of the pages here. If left blank, the default image will be shown
  22. const restOfThePagesImageList = [
  23. "https://imgur.com/eK23SeH.jpg",
  24. "https://i.imgur.com/l9K9IOq.jpg"
  25. ];
  26.  
  27. /* ############################################################################### */
  28. /* ##### DON'T MODIFY ANYTHING BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ##### */
  29. /* ############################################################################### */
  30.  
  31. let homePageImgURL;
  32.  
  33. if(homePageImageList.length) {
  34. homePageImgURL = homePageImageList[Math.floor((Math.random()*homePageImageList.length))];
  35. }
  36.  
  37. let restOfPagesImgURL;
  38.  
  39. if(restOfThePagesImageList.length) {
  40. restOfPagesImgURL = restOfThePagesImageList[Math.floor((Math.random()*restOfThePagesImageList.length))];
  41. }
  42.  
  43. let css = `.customBackground { bottom: 0;
  44. display: block;
  45. height: 100%;
  46. object-fit: cover;
  47. pointer-events: none;
  48. position: fixed;
  49. right: 0;
  50. transition: .2s ease-in-out;
  51. width: 100%;
  52. }
  53. .zindex {
  54. z-index: -1;
  55. }
  56. `;
  57.  
  58. const otherpages = () => {
  59. let inGame = false;
  60. let el = document.querySelector("[class^='background_wrapper']");
  61. if (!el) {
  62. inGame = true;
  63. el = document.querySelector("#__next");
  64. if (!el) return;
  65. const def = document.querySelector(".in-game_backgroundDefault__UDbvo");
  66. if (def) {
  67. def.classList = Array.from(def.classList).filter(cl => cl != 'in-game_backgroundDefault__UDbvo');
  68. }
  69. const partyRoot = document.querySelector(".party_root__EQz_N");
  70. if (partyRoot) {
  71. partyRoot.style.background = "none";
  72. }
  73.  
  74. }
  75. let img = document.querySelector('.customBackground')
  76. if (img) {
  77. if (!inGame) {
  78. img.classList = Array.from(img.classList).filter(cl => cl != 'zindex');
  79. }
  80. return;
  81. }
  82. if (!el || !restOfPagesImgURL) return;
  83. img = document.createElement("img")
  84. img.classList.add("customBackground");
  85. if (inGame) {
  86. img.classList.add("zindex");
  87. } else {
  88. img.classList = Array.from(img.classList).filter(cl => cl != 'zindex');
  89. }
  90.  
  91. img.src = restOfPagesImgURL;
  92. GM_addStyle(css);
  93. el.appendChild(img);
  94. }
  95.  
  96. const updateImage = () => {
  97. let imgEl = document.querySelector('.signed-in-start-page_backgroundImage__IR0w5');
  98. if (!imgEl) {
  99. otherpages();
  100. return;
  101. };
  102. if (!homePageImgURL) return;
  103. imgEl.src = homePageImgURL;
  104. }
  105.  
  106.  
  107.  
  108. new MutationObserver(async (mutations) => {
  109. updateImage()
  110. }).observe(document.body, { subtree: true, childList: true });