Greasy Fork

Greasy Fork is available in English.

Team Duel insta guess

Insta guesses Antarctica in team duels

当前为 2023-01-21 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Team Duel insta guess
// @description  Insta guesses Antarctica in team duels
// @version      1.0.1
// @author       victheturtle#5159
// @license      MIT
// @match        https://www.geoguessr.com/*
// @icon         https://cdn.discordapp.com/icons/975845742629490708/5e06cb2509eec4d731c078ee20bd72d1.webp?size=128
// @namespace    http://greasyfork.icu/users/967692-victheturtle
// ==/UserScript==

let lastRoundGuessed = 0;

async function fetchWithCors(url, method, body) {
    return await fetch(url, {
        "headers": {
            "accept": "*/*",
            "accept-language": "en-US,en;q=0.8",
            "content-type": "application/json",
            "sec-fetch-dest": "empty",
            "sec-fetch-mode": "cors",
            "sec-fetch-site": "same-site",
            "sec-gpc": "1",
            "x-client": "web"
        },
        "referrer": "https://www.geoguessr.com/",
        "referrerPolicy": "strict-origin-when-cross-origin",
        "body": (method == "GET") ? null : JSON.stringify(body),
        "method": method,
        "mode": "cors",
        "credentials": "include"
    });
};

const getGameId = () => location.pathname.split("/")[2];
const getRoundNumberApi = (gameId) => `https://game-server.geoguessr.com/api/duels/${gameId}/`;
const getRoundNumber = async () => await fetchWithCors(getRoundNumberApi(getGameId()), "GET")
                              .then(it => it.json()).then(it => it.currentRoundNumber);
const getGuessApi = (gameId) => `https://game-server.geoguessr.com/api/duels/${gameId}/guess`;

async function guessAntarctica() {
    if (lastRoundGuessed != 0) return "Skipping because already preparing a guess";
    lastRoundGuessed = -1;
    const rn = await getRoundNumber();
    if (rn == lastRoundGuessed) return "Skipping because already guessed";
    lastRoundGuessed = rn;
    return fetchWithCors(getGuessApi(getGameId()), "POST", {"lat": -75.6, "lng": 65.8, "roundNumber": rn})
        .then(it => it.json())
        .then(it => `Sent guess for round ${it.currentRoundNumber}`)
        .catch(e => {lastRoundGuessed = 0; return e;});
};

function doIt() {
    if (!location.href.includes("team-duels")) {
        lastRoundGuessed = 0;
        return;
    }
    const buttons = document.querySelectorAll("[class*='button_wrapper__']");
    const button = (buttons.length >= 2) ? buttons[1] : buttons[0];
    if (button == null || button.innerText != "GUESS") {
        lastRoundGuessed = 0;
        return;
    }
    guessAntarctica()
    .then(out => console.log(out));
}

setInterval(doIt, 200);