// ==UserScript== // @name GeoGuessr Background Replacer // @description Replaces the background of the geoguessr pages with your own image // @version 1.3.2 // @author Tyow#3742 // @match *://*.geoguessr.com/* // @license MIT // @run-at document-start // @require https://unpkg.com/@popperjs/core@2.11.5/dist/umd/popper.min.js // @namespace https://greasyfork.org/users/1011193 // @grant GM_addStyle // @downloadURL none // ==/UserScript== //Add image links for the homePage in this list. If left blank, the default image will be shown const homePageImageList = [ "https://cdn.wallpapersafari.com/6/80/9ZbpYo.jpg", "https://cdn.wallpapersafari.com/25/72/dtkc16.jpg", "https://i.imgur.com/l9K9IOq.jpg", ]; // Add image links for the rest of the pages here. If left blank, the default image will be shown const restOfThePagesImageList = [ "https://imgur.com/eK23SeH.jpg", "https://i.imgur.com/l9K9IOq.jpg" ]; /* ############################################################################### */ /* ##### DON'T MODIFY ANYTHING BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ##### */ /* ############################################################################### */ let homePageImgURL; if(homePageImageList.length) { homePageImgURL = homePageImageList[Math.floor((Math.random()*homePageImageList.length))]; } let restOfPagesImgURL; if(restOfThePagesImageList.length) { restOfPagesImgURL = restOfThePagesImageList[Math.floor((Math.random()*restOfThePagesImageList.length))]; } let css = `.customBackground { bottom: 0; display: block; height: 100%; object-fit: cover; pointer-events: none; position: fixed; right: 0; transition: .2s ease-in-out; width: 100%; } .zindex { z-index: -1; } `; const otherpages = () => { let inGame = false; let el = document.querySelector("[class^='background_wrapper']"); if (!el) { inGame = true; el = document.querySelector("#__next"); if (!el) return; const def = document.querySelector(".in-game_backgroundDefault__UDbvo"); if (def) { def.classList = Array.from(def.classList).filter(cl => cl != 'in-game_backgroundDefault__UDbvo'); } const partyRoot = document.querySelector(".party_root__EQz_N"); if (partyRoot) { partyRoot.style.background = "none"; } } let img = document.querySelector('.customBackground') if (img) { if (!inGame) { img.classList = Array.from(img.classList).filter(cl => cl != 'zindex'); } return; } if (!el || !restOfPagesImgURL) return; img = document.createElement("img") img.classList.add("customBackground"); if (inGame) { img.classList.add("zindex"); } else { img.classList = Array.from(img.classList).filter(cl => cl != 'zindex'); } img.src = restOfPagesImgURL; GM_addStyle(css); el.appendChild(img); } const updateImage = () => { let imgEl = document.querySelector('.signed-in-start-page_backgroundImage__IR0w5'); if (!imgEl) { otherpages(); return; }; if (!homePageImgURL) return; imgEl.src = homePageImgURL; } new MutationObserver(async (mutations) => { updateImage() }).observe(document.body, { subtree: true, childList: true });