GeoGuessr Background Replacer

Replaces the background of the Geoguessr pages with your own image

Versión del día 17/5/2023. Echa un vistazo a la versión más reciente.

// ==UserScript==
// @name         GeoGuessr Background Replacer
// @description  Replaces the background of the Geoguessr pages with your own image
// @version      1.2
// @author       Tyow#3742
// @match        *://*.geoguessr.com/*
// @license      MIT
// @run-at       document-start
// @namespace https://greasyfork.org/users/1011193
// @grant        GM_addStyle
// ==/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://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.hdwallpapers.in%2Fdownload%2Fcolorful_texture_4k_hd_abstract-HD.jpg&f=1&nofb=1&ipt=e2c589746450fa0ac70e46511b9335bc3e2a377962dfc7cdfaa968d0215f9255&ipo=images"];

// Add image links for the rest of the pages here. If left blank, the default image will be shown
const restOfThePagesImageList = ["https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fimages.wallpapersden.com%2Fimage%2Fdownload%2Fminimalist-black-digital-blend_a2pnam2UmZqaraWkpJRobWllrWdma2U.jpg&f=1&nofb=1&ipt=8140d488ce7fa560a021b53bf042bc5e62475fe8524ab07d6b20e0befba675f5&ipo=images"];

/* ############################################################################### */
/* ##### 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% }`;


const otherpages = () => {
    if (document.querySelector('.customBackground')) return;
    let el = document.querySelector("[class^='background_wrapper']");
    if (!el || !restOfPagesImgURL) return;
    let img = document.createElement("img")
    img.className = "customBackground";
    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 });