Greasy Fork

Greasy Fork is available in English.

Geoguessr Team Duels Advanced Options

Adds extra options to team duel settings.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Geoguessr Team Duels Advanced Options
// @description  Adds extra options to team duel settings.
// @version      0.1
// @author       macca#8949
// @license      MIT
// @match        https://www.geoguessr.com/*
// @run-at       document-start
// @grant        none
// @namespace    http://greasyfork.icu/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;
    }

    // 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')) {
        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
});