GeoGuessr Background Replacer

Replaces the background of the geoguessr pages with your own image

目前為 2023-05-18 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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/[email protected]/dist/umd/popper.min.js
// @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://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 });