Geoguessr Old UI Emulator

Re-adds the score bar and moveable end map to Geoguessr

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Geoguessr Old UI Emulator
// @version      1.1
// @description  Re-adds the score bar and moveable end map to Geoguessr
// @author       zakiack
// @match        *://*.geoguessr.com/*
// @license      MIT
// @namespace    https://greasyfork.org/users/1037819
// ==/UserScript==
var ranRes = false;
var ranEnd = false;
function generateBar(score,barPercent,id){
    const barBackground = document.createElement("div");
    const barFill = document.createElement("div");
    const scorePara = document.createElement("p");
    barBackground.id = id;
    barBackground.style.width = "90%";
    barBackground.style.backgroundColor = "grey";
    barBackground.style.textAlign = "center";
    barBackground.style.height = "20px";
    barBackground.style.margin = "auto";
    barFill.style.width = barPercent+"%";
    barFill.style.backgroundColor = "orange";
    barFill.class = "filled bar";
    scorePara.innerHTML = score;
    scorePara.class = "score label";
    barBackground.appendChild(barFill);
    barFill.appendChild(scorePara);
    return barBackground;
}
function addBarDuring(resultElement){
    const score = parseFloat(document.querySelector('div[class^="round-result_pointsIndicatorWrapper"]').firstElementChild.firstElementChild.firstElementChild.innerHTML.replace(/,/g, ''));
    const barPercent = (score/5000)*100;
    let e = document.getElementById("the bar");
    if (e && score){
        const barFill = e.firstElementChild;
        const scorePara = barFill.firstElementChild;
        barFill.style.width = barPercent+"%";
        scorePara.innerHTML = score;

    } else if(!e) {
        const bar = generateBar(score,barPercent,"the bar");
        resultElement.insertBefore(bar,resultElement.firstChild);
    }

}
function addBarEnd(){
    const score = parseFloat(document.querySelectorAll('div[class^="status_value"]')[2].innerHTML.replace(/,/g, ''));
    const resultOverlays = document.querySelectorAll('div[class^="result-overlay_overlay"]');
    if (resultOverlays){
        for (let i=0;i<resultOverlays.length;i++){
            resultOverlays[i].remove();
        }
    }
    const bottomBar = document.querySelector('div[class^="result-layout_contentNew"]');
    const barPercent = (score/25000)*100;
    let e = document.getElementById("the bar end");
    if(!e) {
        const bar = generateBar(score,barPercent,"the bar end");
        let e1 = document.getElementById("the bar");
        bottomBar.insertBefore(bar,e1);
        e1.remove();
        const roundDesc = document.createElement("p");
        roundDesc.innerHTML = "You Scored "+score+" Out of 25,000 points";
        roundDesc.style.fontSize = "20px";
        bottomBar.insertBefore(roundDesc,bar);
    }
}
function checkGameEnd(){
    //if (window.location.href.includes("/game/")){
        const gameLayout = document.querySelector('.game-layout');
        const checkEndingElement = document.querySelector('div[class^="round-indicator_roundIndicatorContent"]');
        const resultElement = document.querySelector('div[class^="result-layout_contentNew"]');
        const endElement = document.querySelector('div[class^="result-map__map"]');
        if(checkEndingElement && checkEndingElement.innerHTML.includes("Result") && ranEnd == false) {
            ranRes = true;
            ranEnd = true;
            addBarEnd();
        }else if(gameLayout && resultElement && ranRes == false) {
            addBarDuring(resultElement);
            ranRes = true;
            ranEnd = false;
        }else if(gameLayout) {
            ranRes = false;
            ranEnd = false;
        }
    //}
}
function init(){
    console.log("zakiack's old geoguessr ui emulator running");
    const observer = new MutationObserver(checkGameEnd);
    observer.observe(document.querySelector('#__next'), { subtree: true, childList: true });
}
init();