Greasy Fork

Greasy Fork is available in English.

GeoGuessr Background Replacer

Replaces the background of the geoguessr pages with your own image

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         GeoGuessr Background Replacer
// @description  Replaces the background of the geoguessr pages with your own image
// @version      1.3.1
// @author       Tyow#3742
// @match        *://*.geoguessr.com/*
// @license      MIT
// @run-at       document-start
// @namespace http://greasyfork.icu/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;
    if (document.querySelector('.customBackground')) return;
    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";
        }

    }
    if (!el || !restOfPagesImgURL) return;
    let img = document.createElement("img")
    img.classList.add("customBackground");
    if (inGame) {
       img.classList.add("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 });