Geoguessr Team Duels Advanced Options

Adds extra options to team duel settings.

目前為 2022-10-07 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Geoguessr Team Duels Advanced Options
// @description  Adds extra options to team duel settings.
// @version      0.1.2
// @author       macca#8949
// @license      MIT
// @match        https://www.geoguessr.com/*
// @run-at       document-start
// @grant        none
// @namespace    https://gf.qytechs.cn/en/scripts/452579-geoguessr-team-duels-advanced-options
// ==/UserScript==

const getGameId = () => {
    return window.location.href.split('/')[4];
}

window.modifySetting = (e, settingName) => {
    let newValue = e.value;
    if (settingName === 'multiplierIncrement') {
        newValue *= 10;
        newValue = Math.round(newValue);
    }

    // Fetch the game options
    fetch(`https://game-server.geoguessr.com/api/lobby/${getGameId()}/join`, {
        "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": "POST",
        "mode": "cors",
        "credentials": "include"
    }).then((response) => response.json())
      .then((data) => {
        let gameOptions = data.gameOptions;
        gameOptions[settingName] = newValue;

        fetch(`https://game-server.geoguessr.com/api/lobby/${getGameId()}/options`, {
            "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": JSON.stringify(gameOptions),
            "method": "PUT",
            "mode": "cors",
            "credentials": "include"
        });
    });
}

let observer = new MutationObserver((mutations) => {
    if (document.querySelector('.game-options_lives__wNSwd') && window.location.href.includes('team-duels') && document.querySelector('.lobby_discardButton__e3luy')) {
        let healthElement = document.querySelector('.game-options_lives__wNSwd').parentElement;
        healthElement.innerHTML = `
        <input type="text" id="health-input" onchange="modifySetting(this, 'initialHealth')" style="text-align: center; background: rgba(255,255,255,0.1); color: white; border: none; border-radius: 5px; width: 60px;"><div class="game-options_optionLabel__dJ_Cy">Health</div>
        `;
        healthElement.style = "display: flex; flex-direction: column; align-items: center; justify-content: center;";

        let multiplierIncrementBox = document.createElement('label');
        multiplierIncrementBox.className = "game-options_option__eCz9o game-options_editableOption__Mpvar";
        multiplierIncrementBox.innerHTML = `
        <input type="text" id="increment-input" onchange="modifySetting(this, 'multiplierIncrement')" style="text-align: center; background: rgba(255,255,255,0.1); color: white; border: none; border-radius: 5px; width: 60px;"><div class="game-options_optionLabel__dJ_Cy">Multiplier Increment</div>
        `;
        multiplierIncrementBox.style = "display: flex; flex-direction: column; align-items: center; justify-content: center;";

        let multiplierBox = document.querySelector('img[alt="damage multiplier icon"]').parentNode.parentNode;
        multiplierBox.parentNode.insertBefore(multiplierIncrementBox, multiplierBox.nextSibling);

        fetch(`https://game-server.geoguessr.com/api/lobby/${getGameId()}/join`, {
            "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": "POST",
            "mode": "cors",
            "credentials": "include"
        }).then((response) => response.json())
          .then((data) => {
            document.querySelector('#health-input').value = data.gameOptions.initialHealth;
            document.querySelector('#increment-input').value = data.gameOptions.multiplierIncrement / 10;
        });
    }
});


observer.observe(document.body, {
  characterDataOldValue: false,
  subtree: true,
  childList: true,
  characterData: false
});

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址