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