Gartic.io Advanced Room Options

Adding more room configuration options in Gartic.io.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Gartic.io Advanced Room Options
// @namespace    http://tampermonkey.net/
// @version      1.7
// @description  Adding more room configuration options in Gartic.io.
// @author       arcticrevurne
// @icon         https://em-content.zobj.net/source/twitter/408/fox_1f98a.png
// @match        *://*.gartic.io/*
// @license      MIT
// @noframes
// ==/UserScript==

(function() {
    'use strict';

    function waitForElement(selector, callback) {
        const initialElement = document.querySelector(selector);
        if (initialElement) {
            callback(initialElement);
            return;
        }

        const observer = new MutationObserver(mutations => {
            const element = document.querySelector(selector);
            if (element) {
                observer.disconnect();
                callback(element);
            }
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }

    function customizeDropdown(selectSelector, customOptions, defaultSelectedValue) {
        let isModifying = false;

        const performModification = (selectElement) => {
            if (isModifying) {
                return;
            }
            isModifying = true;

            const currentSelectedValue = selectElement.value;
            let valueToSet = defaultSelectedValue;

            if (customOptions.includes(parseInt(currentSelectedValue))) {
                valueToSet = parseInt(currentSelectedValue);
            }

            while (selectElement.firstChild) {
                selectElement.removeChild(selectElement.firstChild);
            }

            customOptions.forEach(value => {
                const option = document.createElement('option');
                option.value = value;
                option.textContent = value;
                selectElement.appendChild(option);
            });

            if (valueToSet !== undefined && customOptions.includes(valueToSet)) {
                selectElement.value = valueToSet;
            } else if (selectElement.options.length > 0) {
                 selectElement.value = selectElement.options[0].value;
            }

            selectElement.dispatchEvent(new Event('change', { bubbles: true }));

            isModifying = false;
        };

        waitForElement(selectSelector, (selectElement) => {
            setTimeout(() => {
                performModification(selectElement);

                const observer = new MutationObserver(mutations => {
                    if (isModifying) {
                        return;
                    }

                    let shouldRemodify = false;
                    for (let mutation of mutations) {
                        if (mutation.type === 'childList' || (mutation.type === 'attributes' && mutation.attributeName === 'value')) {
                            if (selectElement.options.length !== customOptions.length ||
                                !customOptions.every(val => Array.from(selectElement.options).some(opt => parseInt(opt.value) === val))) {
                                shouldRemodify = true;
                                break;
                            }
                        }
                    }

                    if (shouldRemodify) {
                        performModification(selectElement);
                    }
                });

                observer.observe(selectElement, { childList: true, subtree: true, attributes: true, attributeFilter: ['value'] });

            }, 500);
        });
    }

    const desiredPlayerOptions = [];
    for (let i = 5; i <= 75; i++) {
        desiredPlayerOptions.push(i);
    }

    for (let i = 75 + 25; i <= 255; i += 25) {
        if (!desiredPlayerOptions.includes(i)) {
             desiredPlayerOptions.push(i);
        }
    }

    desiredPlayerOptions.push(255);
    desiredPlayerOptions.sort((a, b) => a - b);

    customizeDropdown(
        'select[name="players"]',
        desiredPlayerOptions,
        15
    );

    const desiredPointsOptions = [];

    for (let i = 70; i <= 720; i += 10) {
        desiredPointsOptions.push(i);
    }
    for (let i = 720 + 240; i <= 7200; i += 240) {
        if (!desiredPointsOptions.includes(i)) {
             desiredPointsOptions.push(i);
        }
    }

    desiredPointsOptions.push(65535);
    desiredPointsOptions.sort((a, b) => a - b);

    customizeDropdown(
        'select[name="points"]',
        desiredPointsOptions,
        120
    );

})();