Greasy Fork

Greasy Fork is available in English.

Hedge Streak Counter (Automated)

Adds a hedge streak counter to the GeoGuessr website. Compatible with country streak counters if both scripts are at least v.1.3.0.

当前为 2022-10-09 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Hedge Streak Counter (Automated)
// @version      1.3.0
// @description  Adds a hedge streak counter to the GeoGuessr website. Compatible with country streak counters if both scripts are at least v.1.3.0.
// @author       victheturtle#5159
// @license      MIT
// @match        https://www.geoguessr.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=geoguessr.com
// @namespace    http://greasyfork.icu/users/967692-victheturtle
// ==/UserScript==

// Credits to quarksauce for the original Hedge Streak Counter script. My only contribution was to make it compatible with the Country Streak Counter

const HEDGE_THRESHOLD = 20000;


if (sessionStorage.getItem("HedgeStreak") == null) {
    sessionStorage.setItem("HedgeStreak", 0);
};
if (sessionStorage.getItem("Checked") == null) {
    sessionStorage.setItem("Checked", 0);
};

let streak = parseInt(sessionStorage.getItem("HedgeStreak"), 10);
let lastGameId = sessionStorage.getItem("HedgeLastGameId");

function checkGameMode() {
    return (location.pathname.startsWith("/game/"));
};

function geoguessrStyle(number) {
    return `<div class="guess-description-distance_distanceLabel__23Opn">
                <div class="styles_root__eoNIJ styles_variantWhiteTransparent__20ADs styles_roundnessSmall__ZbRvs">
                    <div class="styles_start__u_cL2 styles_right__hZg0u"></div>
					<div class="guess-description-distance_distanceValue__BRuXF">${number}</div>
					<div class="styles_end__euu3r styles_right__hZg0u"></div>
				</div>
			</div>`;
};

function addCounter() {
	if (!checkGameMode()) {
		return;
	};
    if (document.getElementById("hedge-streak") == null && document.getElementsByClassName("status_section__8uP8o").length >= 3) {
        let newDiv = document.createElement("div");
        newDiv.className = 'status_section__8uP8o';
        document.getElementsByClassName("status_inner__1eytg")[0].appendChild(newDiv);
        newDiv.innerHTML = `<div class="status_label__SNHKT">Hedge</div><div id="hedge-streak" class="status_value__xZMNY">${streak}</div>`;
    }
};

function addStreakGameSummary() {
    if (document.getElementById("hedge-streak2") == null && !!document.querySelector('.standard-final-result_section___B3ne')) {
        let newDiv = document.createElement("div");
        let progressSection = document.getElementsByClassName("standard-final-result_progressSection__6jL1y")[0];
        progressSection.parentNode.insertBefore(newDiv, progressSection);
        progressSection.style.marginTop = "10px";
        progressSection.style.marginBottom = "10px";
        newDiv.innerHTML = `<div id="hedge-streak2" style="text-align:center;margin-top:10px;"><h2><i>Hedge Streak: ${streak}</i></h2></div>`;
    };
};

function updateStreak(newStreak) {
    sessionStorage.setItem("HedgeStreak", newStreak);
    if (document.getElementById("hedge-streak") != null) {
        document.getElementById("hedge-streak").innerHTML = newStreak;
    };
    if (document.getElementById("hedge-streak2") != null &&
       (!!document.querySelector('div[data-qa="guess-description"]') || !!document.querySelector('.standard-final-result_section___B3ne'))) {
        document.getElementById("hedge-streak2").innerHTML = `<h2><i>Hedge Streak: ${newStreak}</i></h2>`;
		if (newStreak == 0) {
			if (streak >= 2) {
                document.getElementById("hedge-streak2").innerHTML = `<h2><i>Hedge Streak: 0</i></h2>
                    Your hedge streak ended after ${geoguessrStyle(streak)} seeds.`;
			} else if (streak == 1) {
				document.getElementById("hedge-streak2").innerHTML = `<h2><i>Hedge Streak: 0</i></h2>
                    Your hedge streak ended after ${geoguessrStyle(1)} seed.`;
			};
		};
    };
    streak = newStreak;
};

function check() {
    const gameId = window.location.href.substring(window.location.href.lastIndexOf('/') + 1);

    if (checkGameMode() && gameId != lastGameId) {
        let apiUrl = "https://www.geoguessr.com/api/v3/games/" + gameId;
        fetch(apiUrl)
        .then(res => res.json())
        .then((out) => {
            if (out.state == "finished") {
                if (parseInt(out.player.totalScore.amount, 10) >= HEDGE_THRESHOLD) {
                    updateStreak(streak+1);
                    lastGameId = gameId;
                    sessionStorage.setItem("HedgeLastGameId", lastGameId);
                } else {
                    updateStreak(0);
                }
            };
        }).catch(err => { throw err; });
    };
};

function doCheck() {
    if (!document.querySelector('.result-layout_root__NfX12')) {
        sessionStorage.setItem("HedgeChecked", 0);
    } else if (sessionStorage.getItem("HedgeChecked") == 0) {
        check();
        sessionStorage.setItem("HedgeChecked", 1);
    }
};

function tryAddCounter() {
    addCounter();
    for (let timeout of [400,1200,2000,3000,4000]) {
        if (document.getElementsByClassName("status_section__8uP8o").length == 0) {
            setTimeout(addCounter, timeout);
        };
    }
};

function tryAddCounterOnRefresh() {
    setTimeout(addCounter, 50);
    setTimeout(addCounter, 300);
};

function tryAddStreak() {
	if (!checkGameMode()) {
		return;
	};
    doCheck();
    for (let timeout of [250,500,1200,2000]) {
        setTimeout(doCheck, timeout);
    }
    for (let timeout of [250,500,1200,2000]) {
        setTimeout(addStreakGameSummary, timeout);
    }
};

document.addEventListener('keypress', (e) => {
    switch (e.key) {
        case '5':
            updateStreak(streak + 1);
            break;
        case '6':
            updateStreak(streak - 1);
            break;
        case '9':
            updateStreak(0);
    }
});

document.addEventListener('click', tryAddCounter, false);
document.addEventListener('click', tryAddStreak, false);
document.addEventListener('load', tryAddCounterOnRefresh(), false);