[Pokeclicker] Additional Visual Settings

Adds additional settings for hiding some visual things to help out with performance. Also, includes various features that help with ease of accessibility.

// ==UserScript==
// @name          [Pokeclicker] Additional Visual Settings
// @namespace     Pokeclicker Scripts
// @author        Ephenia (Credit: Optimatum)
// @description   Adds additional settings for hiding some visual things to help out with performance. Also, includes various features that help with ease of accessibility.
// @copyright     https://github.com/Ephenia
// @license       GPL-3.0 License
// @version       3.0

// @homepageURL   https://github.com/Ephenia/Pokeclicker-Scripts/
// @supportURL    https://github.com/Ephenia/Pokeclicker-Scripts/issues

// @match         https://www.pokeclicker.com/
// @icon          https://www.google.com/s2/favicons?domain=pokeclicker.com
// @grant         unsafeWindow
// @run-at        document-idle
// ==/UserScript==

// TODO disable party attack number + tooltip

class AdditionalVisualSettings {
    static graphicsDisabledSettings = {
        route: {
            header: ko.observable(false),
            pokemon: ko.observable(false),
            catchIcon: ko.observable(false),
            healthbar: ko.observable(false),
            attack: ko.observable(false),
        },
        gym: {
            header: ko.observable(false),
            timer: ko.observable(false),
            pokemon: ko.observable(false),
            healthbar: ko.observable(false),
            attack: ko.observable(false),
        },
        dungeon: {
            header: ko.observable(false),
            timer: ko.observable(false),
            images: ko.observable(false),
            attack: ko.observable(false),
        },
        battleFrontier: {
            header: ko.observable(false),
            timer: ko.observable(false),
            pokemon: ko.observable(false),
            healthbar: ko.observable(false),
        },
    };
    static autoClickerIntegration = ko.observable(JSON.parse(localStorage.getItem('AVSautoClickerIntegration') || 'false'));
    // Disable graphics unless autoclicker integration is on and autoclicker is not running
    static graphicsSettingsActive = ko.computed({
        read: () => !(typeof EnhancedAutoClicker === 'function' && this.autoClickerIntegration() && !EnhancedAutoClicker.autoClickState()),
        deferEvaluation: true
    });

    static loadGraphicsSettings() {
        try {
            const savedSettings = JSON.parse(localStorage.getItem('AVSgraphicsDisabledSettings') || '{}');
            Object.keys(this.graphicsDisabledSettings).forEach(state => {
                Object.keys(this.graphicsDisabledSettings[state]).forEach(setting => {
                    if (savedSettings[state]?.[setting] != undefined) {
                        const val = !!savedSettings[state][setting];
                        this.graphicsDisabledSettings[state][setting](val);
                    }
                });
            });
        } catch {
            this.saveGraphicsSettings();
        }
    }

    static saveGraphicsSettings() {
        const settingsToSave = {};
        Object.keys(this.graphicsDisabledSettings).forEach(state => {
            settingsToSave[state] = {};
            Object.keys(this.graphicsDisabledSettings[state]).forEach(setting => {
                settingsToSave[state][setting] = this.graphicsDisabledSettings[state][setting]();
            });
        });
        localStorage.setItem('AVSgraphicsDisabledSettings', JSON.stringify(settingsToSave));
    }

    static initOnLoad() {
        this.addGraphicsBindings();
        this.addOptimizeVitamins();
    }

    static initVisualSettings() {
        this.loadGraphicsSettings();

        // Add shortcut menu icons
        const getMenu = document.getElementById('startMenu');
        const shortcutsToAdd = [
            ['quick-settings', '#settingsModal', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAMAAADW3miqAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAkZQTFRFAAAAAAAAAAAAAAAAAAAAAAAAAAAAU1tsSEhgGyM0AAAAu8Pcu8PUwMDYKSk5AAAAAAAAoqq7AAAAAAAAe3uUxMTdu8TcvcXet7fIgJGiAAAAs7vUwsLTx8fYw8PUt8jZAAAAAAAAZWV2v7/hMTlKtLS8vMTVucLavMTdAAAAAAAASEhIJycncXFxcXl5c3N7cnJyZmZmu7vUAAAAAAAAtLzNv7/QRERE////t7e3xMTEQEBAFRUVdHR8aGhwAAAAdXV1vLzNc3OEAAAACgoKs7vLAgIKdHR0dXV9BgYOtLzEAAAAAAAAAAAAe4OTOjpCVFRcKTE5xMTVAAABBgYGbW11b29vAAAAAAAArr/QtsfYpqa3MDAwAA0eAFZnAFZ4AA0vAAAAEBAQvcbWMjtLISEhAEVnAJO0CbbfAKHUAJK0AAAeb2+ACQkJv7/YSUlaNDQ0IYepAJC5AI3AISEyvb3Wa3OEXWV2HT8/DZW3AJKzCZGzAAAICSsrAAUFAHudAIytAGuNKTFCMjJLRUVWACYmAHmSACwsDAwMICAgAAAAm5u0RUVFAAojABMjvLzecnJ7YWFyKSk6Y2t7S0tLBwcHAAANh4eYAAAJanJybXV1VFRUAgoKrq6uAgIDNjpTVGVlWlpaeXl5cnt7CgoTqqqzmpqqOztbMTlKY2N4na6uKioqERERcnJ6ChMTvLzVY2N4YGF2wMDiMjIyCAgIExsbtLTEOj1FjIydOkBAs8TVL0BAWWp7YmJzkpqzc3uMdnaHAAAAI+eLBgAAAMJ0Uk5TABFE/6rdd////2b/////iFX/Qv3////////v//////+E4f////////9x3P//////////5fv/////////////Uf///zP/////////DzGo////////////u+7//////////yL/////////////////////////////////////////////////////if//////////////////////////E///////////DAP/////////gv///////////////////5k2RgJ2AAACq0lEQVR4nJXUaVfTQBQGYPBFUZNqtTRFKa3SElCBVqQQLNEARXFfqtgGt4qKYkVQEEXcxR1w38UdRcUNrIr7P3MmCdDQw+F4P83JPHPv5E4mcXH/HfGjijEAErTxWIwbiSSO1+aACcDEGEMIw7CGSZhsNBqBKSxL2DAz1ZRk5khYoEQyHU8D9HucbjKrKMVqTU212ejYnqzPNWNmmsPBWQwGp5rJmc5nZHCZejRrtoKcmIOs7ByXey6cubkEGXXl5uU5PPkoEArne4tEGguQzjuH7XyhycEDAqlUCAWJEopLUKpDeb6yRYtVVFBerrIlS6P3tGz5CthXrlKRoGUSxdVr1voHUpWaTGTOtk4S10MQBK+3osKtIBd4v3+DigIIynKwcqMkutw+YNPmLVtVJGYFS2g/QvRAtskcV7U9J4c+37Gzetfumj1hOg5Le2tZfp+yMdQRxMDlohOor95/oKa+QSQZCGpkec9BBTWxFKkVDh2ubm5uPtIikhcIh8FwHNsUg45qSO3ZCOjYcYJOnGwRaChIrlPQKQ/PNp6ukCg603qWBM7RTOcvoGoAXQT8ibWXLiuoobWtrb3d7ZYI8vq8tDlq20PjSPUOEOQmA1ESr9DXRF3YZwtevTb03Seg4/oNUSS9vKkh0hCvz04WBQZvROjW7cw7dDmyB05OvIsyt9LtqHvAMLgH3B9CDx7y6HwUjUJ4LCfjyVO17+Rrevb8hacLL191RyEjXstW65u3PT3a2b57zzm6PnR+7NaVqyWN+yT39uFzUVFfL2OwcI5IEr7oqn1Vkd1eXJyfn2KhV8ocieCbfuP9/eR5pgfffzT91JB52B2OB9LI81/qtUPEwDJMJfQdiKP/Efz+oy0FDGwXYg3dlx+BwbwkjDFEmRu8ZvGBv7FZRol/3T2xhRzFta4AAAAASUVORK5CYII='],
            ['quick-inventory', '#showItemsModal', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADgAAAA4BAMAAABaqCYtAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAACdQTFRFAAAA0KhgoHhA+PCw+OB46MhgQEhoqKioeHh4WFhYuEgA2GgAgCgAQaYPaAAAAA10Uk5TAP///////////////y0EQa0AAAH3SURBVHictdTNkpNAEABg5IBXe7bgnGGJOSuU3kmT8koq4xnWdZKjFasSHsBKyBuQV/AR9OKj2TP8zMCa1YtdRULPR1MzTIPj/D1ewKsbieO4d/Fbk93Hb2aOncbJkLvL2L7UjacYm9L5J8K0zyLCd+sBcxYnaBCXMfeH+0CAiFnRZt6GkhJmA0KEKLrUFYgpDOgBPKKAoM1KELgCKAyynIUh6AhD7vMRBms1xzaSdF6OK40pHVcyjK3Af0W9lBFaS3kWHf4UmWOjPdsnqErfH49fVeEIS4WoTCkqDCx8pBGsFdbqbGVjsKeRD7WOb3S6KA16wWGM27IwyI50X4LuZ3XkBt1wt9+gLqJyzBancHgG7l3y+rzf9Jgtqofl0Ln3ccJ354PsYlud2LLvXFdtA9vV9VVHXZ+42qTZgBEwOQSH1CDNPULVPG0AYEpDBmklmS905NS3Bj1kcorff/74pXErL9fbWNUyuoWefICbSC30DNJLNEVhLeV/4ZyOHgnWwjwhQhodUAiFhUHfxtzGTPA819W6yveZ2PRIl3LwgbfIIAdGd+la7DMAvefA228CoyMA+Nh3Ju3+GGnA9CZtm43y4NixraQV5ynWzbWLSz3Bl9Xl0mPTnL+M0NOVTaMuocpihI6k4Ua9ZPTXSGcSnplPMbU/xm/a6CAG6AGINQAAAABJRU5ErkJggg=='],
            ['quick-pokedex', '#pokedexModal', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAWz3pUWHRSYXcgcHJvZmlsZSB0eXBlIGV4aWYAAHjarZtpduQ6doT/cxVeAjEDy8F4jnfg5fsLgJkaq/zc3VJJmUqSGO4QNwJAXfN//ntd/8VXzMZfPqQcS4w3X774Yitv8n2+6v5tbr9/n6/+vJqvn1/vC5aPHK/u/Jnjc//rc/Nu4LxU3oVPDeWnIdO+Xij+aT9/a+jpyGlEljfjaag8DTl7LpingXqmdceS0+cptHlen+ePGbKmxq8y9q23Kc9ovv3tE9YbgX6ctdMZd/PbOnsG4PRjL1d5E/htXOBG87xP/ObrGQkG+c1O96dRXT+88npn/vD5N6e4eD6/+OCrMeP79dfPTfjd+Nc28aeeXX/3/OXz0F4W+2pk/aw18rXWPLOrPmLS+EzqNZX9jhsbJnf7sch34ifwPu3vwne+iN6OyweB2fjuphiLW5bxZphqlpn7tZvOEL2dNvFqbbduf5ZdssV2d194yOvbLJtcccNlnNlxr+NT+x6L2f2W3V03mY6H4U5raMwc99v/zPcfG1pLIW/Mnd+2YlxWQcgw5Dn95i4cYtYrjsI28Ov7+5f86vBg2GbOTLDe7TTRgnliS3HktqMdNwZeT66ZNJ4GMBF9BwZjHB64I8FvormTtckY7JjxT6WhbJ23DReYEOxglNY7F3FOtuqbZ5LZ99pgz8dgFo4ILpJIGQdVfCVgI36Sz8RQDS74EEIMKeRQQo0u+hhijCkK/GpyyaeQYkopp5JqdtnnkGNOOV+55FpscYBjKLGkkksptdJppeXK05Ubam22ueZbaLGllltptRM+3ffQY089X730OuxwA5wYcaSRRxl1mkkoTT/DjDPNPMusi1BbbvkVVlxp5VVWfXvNXMetP77/udfMy2t2e0o3prfXeDSlVxNGcBLkMzxmvcHjSR4goK18dlNDvL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JlYXRvcj4KICAgIDxyZGY6U2VxLz4KICAgPC9wbHVzOkltYWdlQ3JlYXRvcj4KICAgPHBsdXM6Q29weXJpZ2h0T3duZXI+CiAgICA8cmRmOlNlcS8+CiAgIDwvcGx1czpDb3B5cmlnaHRPd25lcj4KICAgPHBsdXM6TGljZW5zb3I+CiAgICA8cmRmOlNlcS8+CiAgIDwvcGx1czpMaWNlbnNvcj4KICA8L3JkZjpEZXNjcmlwdGlvbj4KIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAKPD94cGFja2V0IGVuZD0idyI/Pn9Za1QAAAAGYktHRAD/AP8A/6C9p5MAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAAHdElNRQfmBQ8NESISKzy+AAAA3ElEQVQoz5WSIXrDMAyFf3cBA4MBPYKPIRjoIwwWFg7mCIU+QqCgoeBgYGDhQA4wpoLGWZaFTMRP+t57ki0HdiEivs3NLGzzZk+8mO0d/I9QRHwAH2P07/zhY4w+xugD+ADeg1fDUxXFGInXBO/981xqAHHT8EVE/GJG27bMnxPt6xfTTVfCPM8AvN3vINI3WyeA6aZcz2cO71NHqoSKSymklMgiTxPAFtwAlFLoum4V5Zx/8EJMKaGqhPpKpZSVVMUppbWmqphZOB251pGOIuwXtyeq6q+Nh/9+jQcRyGEasqbeQgAAAABJRU5ErkJggg=='],
        ];
        shortcutsToAdd.forEach(([id, modal, source]) => {
            const quickElem = document.createElement('img');
            quickElem.id = id;
            quickElem.src = source;
            quickElem.setAttribute('href', modal);
            quickElem.setAttribute('data-toggle', 'modal');
            getMenu.prepend(quickElem);
        });

        // Add AVS settings options to scripts tab
        const settingsBody = createScriptSettingsContainer('Additional Visual Settings');

        let elem = document.createElement('tr');
        elem.innerHTML = `<td class="p-2" colspan="2"><label class="m-0">Disable battle visuals</label></td>`;
        settingsBody.appendChild(elem);

        // Graphics-disabling settings
        Object.keys(this.graphicsDisabledSettings).forEach(state => {
            elem = document.createElement('tr');
            elem.innerHTML = `<th class="p-2 col-md-5" scope="row">${GameConstants.camelCaseToString(state)}</th><td class="p-2" style="display:flex;"></td>`;
            let innerElem = elem.querySelector('td');
            Object.keys(this.graphicsDisabledSettings[state]).forEach(setting => {
                const container = document.createElement('div');
                container.className = 'px-3'
                container.innerHTML = `${GameConstants.camelCaseToString(setting)} <input id="checkbox-AVS-${state}-${setting}" type="checkbox" class="mx-1"></td>`;
                const checkbox = container.querySelector('input');
                checkbox.checked = this.graphicsDisabledSettings[state][setting]();
                checkbox.addEventListener('change', event => {
                    this.graphicsDisabledSettings[state][setting](event.target.checked);
                    this.saveGraphicsSettings();
                });
                innerElem.appendChild(container);
            });
            settingsBody.appendChild(elem);
        });

        // EnhancedAutoClicker integration setting, if the script is present
        if (typeof EnhancedAutoClicker === 'function') {
            elem = document.createElement('tr');
            elem.innerHTML = `<td class="p-2" colspan="2"><label class="m-0" for="checkbox-AVS-autoClickerIntegration">Disable graphics only when EnhancedAutoClicker is on</label>` + 
                `<input id="checkbox-AVS-autoClickerIntegration" type="checkbox" class="mx-2"></td>`;
            settingsBody.appendChild(elem);
            const checkbox = elem.querySelector('input');
            checkbox.checked = this.autoClickerIntegration();
            checkbox.addEventListener('change', event => {
                this.autoClickerIntegration(event.target.checked);
                localStorage.setItem('AVSautoClickerIntegration', this.autoClickerIntegration());
            });
        }

        // Create travel shortcut buttons on town map
        const travelShortcutsToAdd = [
            ['dock-button', 'Dock', {left: 32, top: 0}, MapHelper.openShipModal],
            ['gyms-button', 'Gyms', {left: 75, top: -8}, () => { AdditionalVisualSettings.generateRegionGymsList(); $('#gymsShortcutModal').modal('show'); }],
            ['dungeons-button', 'Dungeons', {left: 121, top: -8}, () => { AdditionalVisualSettings.generateRegionDungeonssList(); $('#dungeonsShortcutModal').modal('show'); }],
        ];

        travelShortcutsToAdd.forEach(([id, name, pos, func]) => {
            const button = document.createElement('button');
            button.id = id;
            button.textContent = name;
            button.className = 'btn btn-block btn-success';
            button.style = `position: absolute; left: ${pos.left}px; top: ${pos.top}px; width: auto; height: 41px; font-size: 11px;`;
            button.addEventListener('click', func);
            document.getElementById('townMap').appendChild(button);
        });

        // Prevent ship modal sequence-breaking
        document.getElementById('dock-button').setAttribute('data-bind', 'enabled: TownList[GameConstants.DockTowns[player.region]].isUnlocked()');
        ko.applyBindings(App.game, document.getElementById('dock-button'));

        // Create gym and dungeon shortcut modals
        const modalNames = ['gyms', 'dungeons'];
        const fragment = new DocumentFragment();
        for (const name of modalNames) {
            const customModal = document.createElement('div');
            customModal.setAttribute('class', 'modal noselect fade');
            customModal.setAttribute('tabindex', '-1');
            customModal.setAttribute('role', 'dialogue');
            customModal.setAttribute('id', `${name}ShortcutModal`);
            customModal.setAttribute('aria-labelledby', `${name}ShortcutModalLabel`);
            customModal.innerHTML = `<div class="modal-dialog modal-dialog-scrollable modal-dialog-centered modal-sm" role="document">
                <div class="modal-content">
                    <div class="modal-header" style="justify-content: space-around;">
                        <h5 id="${name}-shortcut-modal-title" class="modal-title"></h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                    </div>
                    <div class="modal-body bg-ocean">
                        <div id="${name}-shortcut-buttons"></div>
                    </div>
                </div>
            </div>`;
            fragment.appendChild(customModal);
        }
        document.getElementById('ShipModal').after(fragment);

        addGlobalStyle('.pageItemTitle { height:38px }');
        addGlobalStyle('#quick-settings, #quick-inventory, #quick-pokedex { height: 36px; background-color: #eee; border: 4px solid #eee; cursor: pointer; image-rendering: pixelated; }');
        addGlobalStyle('#quick-pokedex { padding: 2px; }')
        addGlobalStyle(':is(#quick-settings, #quick-inventory, #quick-pokedex):hover { background-color:#ddd; border: 4px solid #ddd; }');
        addGlobalStyle('#shortcutsContainer { display: block !important; }');
        addGlobalStyle('.gyms-shortcut-leaders { display: flex; pointer-events: none; position: absolute; height: 36px; top: 0; left: 0; image-rendering: pixelated; }');
        addGlobalStyle('.gyms-shortcut-badges { position: absolute; height: 36px; display: flex; top: 0; right: 0; }');
        addGlobalStyle('.dungeons-shortcut-costs { position: relative; margin-right: 12px; filter: none !important }');
        addGlobalStyle('#dungeons-shortcut-buttons > button:hover { -webkit-animation: bounceBackground 60s linear infinite alternate; animation: bounceBackground 60s linear infinite alternate; }');
        addGlobalStyle('#dungeons-shortcut-buttons > button * { z-index: 2 }');
        addGlobalStyle('.dungeons-shortcut-overlay { width: 100%; height: 100%; position: absolute; background-color: rgba(0,0,0,0.45); margin-top: -6px; margin-left: -8px; z-index: 1 !important }');
        addGlobalStyle('.dungeons-shortcut-info { position: relative; font-weight: bold }');
    }

    static generateRegionGymsList() {
        const gymsBtns = document.getElementById('gyms-shortcut-buttons');
        const gymsHead = document.getElementById('gyms-shortcut-modal-title');
        gymsHead.textContent = `Gym Select (${GameConstants.camelCaseToString(GameConstants.Region[player.region])})`;
        gymsBtns.innerHTML = '';
        const fragment = new DocumentFragment();
        const regionGyms = Object.values(GymList).filter((gym) => gym.parent?.region === player.region);
        for (const gym of regionGyms) {
            const hasBadgeImage = !(BadgeEnums[gym.badgeReward].startsWith('Elite') || BadgeEnums[gym.badgeReward] == 'None');
            const badgeImage = (hasBadgeImage ? `assets/images/badges/${BadgeEnums[gym.badgeReward]}.svg` : '');
            const btn = document.createElement('button');
            btn.setAttribute('style', 'position: relative;');
            btn.setAttribute('class', 'btn btn-block btn-success');
            btn.addEventListener('click', () => {
                if (!MapHelper.isTownCurrentLocation(gym.parent.name)) {
                    MapHelper.moveToTown(gym.parent.name);
                }
                $("#gymsShortcutModal").modal("hide");
                GymRunner.startGym(gym); 
            });
            btn.disabled = !(gym.isUnlocked() && gym.parent.isUnlocked());
            btn.innerHTML = `<div class="gyms-shortcut-leaders">
                <img src="${gym.imagePath}" onerror="{ this.src='assets/images/npcs/specialNPCs/Mysterious Trainer.png'; }">
                </div>
                <div class="gyms-shortcut-badges">
                <img src="${badgeImage}" onerror="{ this.onerror=null; this.style.display='none'; }">
                </div>
                ${gym.leaderName}`;
            fragment.appendChild(btn);
        }
        gymsBtns.appendChild(fragment);
    }

    static generateRegionDungeonssList() {
        const dungeonsBtns = document.getElementById('dungeons-shortcut-buttons');
        const dungeonsHead = document.getElementById('dungeons-shortcut-modal-title');
        dungeonsHead.textContent = `Dungeon Select (${GameConstants.camelCaseToString(GameConstants.Region[player.region])})`;
        dungeonsBtns.innerHTML = '';
        const fragment = new DocumentFragment();
        const dungeonTowns = Object.values(TownList).filter((town) => (town.region === player.region && town.constructor.name === 'DungeonTown' && town.dungeon != null));
        for (const town of dungeonTowns) {
            const dungeon = town.dungeon;
            const dungeonClears = App.game.statistics.dungeonsCleared[GameConstants.getDungeonIndex(dungeon.name)]();
            const canAffordEntry = App.game.wallet.currencies[GameConstants.Currency.dungeonToken]() >= dungeon.tokenCost;
            const canAccess = town.isUnlocked() && dungeon.isUnlocked() && canAffordEntry;
            const btn = document.createElement('button');
            btn.setAttribute('style', `position: relative; background-image: url("assets/images/towns/${dungeon.name}.png"); background-position: center;opacity: ${canAccess ? 1 : 0.70}; filter: brightness(${canAccess ? 1 : 0.70});`);
            btn.setAttribute('class', 'btn btn-block btn-success');
            btn.addEventListener('click', () => {
                if (!MapHelper.isTownCurrentLocation(town.name)) {
                    MapHelper.moveToTown(town.name);
                }
                $('#dungeonsShortcutModal').modal('hide');
                DungeonRunner.initializeDungeon(dungeon);
            });
            btn.disabled = !canAccess;
            btn.innerHTML = `<div class="dungeons-overlay"></div>
                <div class="dungeons-shortcut-costs">
                <img src="assets/images/currency/dungeonToken.svg" style="height: 24px; width: 24px;">
                <span style="font-weight: bold;color: ${canAffordEntry ? 'greenyellow' : '#f04124'}">${dungeon.tokenCost.toLocaleString('en-US')}</span>
                </div>
                <div class="dungeons-shortcut-info">
                <span>${dungeon.name}</span>
                <div>${dungeonClears.toLocaleString('en-US')} clears</div>
                </div>`;
            fragment.appendChild(btn);
        }
        dungeonsBtns.appendChild(fragment);
    }

    // Must execute before game loads and applies knockout bindings
    static addGraphicsBindings() {
        function selectorWorkaround(element, selector) {
            try {
                return element.querySelector(selector);
            } catch {
                const [, outer, inner] = selector.match(/(.+):has\((.+)\)/);
                const innerElem = element.querySelector(`${outer} ${inner}`);
                return Array.from(element.querySelectorAll(outer)).find(e => e.contains(innerElem));
            }
        }

        const selectors = {
            route: {
                container: '#routeBattleContainer',
                header: '.pageItemTitle > div:has(> knockout)',
                pokemon: 'div:has(> knockout[data-bind*="pokemonSpriteTemplate"])',
                catchIcon: 'div.catchChance',
                healthbar: 'div.progress.hitpoints',
                attack: '.pageItemFooter knockout[data-bind*="pokemonAttackTemplate"]',
            },
            gym: {
                container: '#battleContainer div[data-bind="if: App.game.gameState === GameConstants.GameState.gym"]',
                header: [
                    ['h2.pageItemTitle > knockout:has(knockout[data-bind*="pokemonNameTemplate"])', 'before'],
                    ['h2.pageItemTitle > knockout:has(span[data-bind*="pokemonsDefeatedComputable"])', 'after']
                ],
                timer: 'h2.pageItemTitle .timer',
                pokemon: 'div:has(> knockout[data-bind*="pokemonSpriteTemplate"])',
                healthbar: 'div.progress.hitpoints',
                attack: '.pageItemFooter knockout[data-bind*="pokemonAttackTemplate"]',
            },
            dungeon: {
                container: '#battleContainer div[data-bind="if: App.game.gameState === GameConstants.GameState.dungeon"]',
                header: [
                    ['h2.pageItemTitle > knockout:has(knockout[data-bind*="pokemonNameTemplate"])', 'before'],
                    ['h2.pageItemTitle > knockout:has(span[data-bind*="defeatedTrainerPokemon"])', 'after']
                ],
                timer: 'h2.pageItemTitle .timer',
                images: [
                    ['h2.pageItemTitle', 'after'],
                    ['h2.pageItemFooter', 'before']
                ],
                attack: '.pageItemFooter knockout[data-bind*="pokemonAttackTemplate"]',
            },
            battleFrontier: {
                container: '#battleContainer div[data-bind="if: App.game.gameState == GameConstants.GameState.battleFrontier"]',
                header: [
                    ['h2.pageItemTitle > knockout:has(knockout[data-bind*="pokemonNameTemplate"])', 'before'],
                    ['h2.pageItemTitle > knockout[data-bind*="pokemonLeftImages"]', 'after']
                ],
                timer: 'h2.pageItemTitle .timer',
                pokemon: 'div:has(> knockout[data-bind*="pokemonSpriteTemplate"])',
                healthbar: 'div.progress.hitpoints',                
            },
        };

        Object.keys(this.graphicsDisabledSettings).forEach(state => {
            const container = document.querySelector(selectors[state]?.container)
            if (!container) {
                console.error(`AVS: could not find ${state} container`);
                return;
            }
            Object.keys(this.graphicsDisabledSettings[state]).forEach(setting => {
                if (!selectors[state]?.[setting]) {
                    return;
                }
                const selector = selectors[state][setting];
                const binding = `ko ifnot: AdditionalVisualSettings.graphicsDisabledSettings.${state}.${setting}() && AdditionalVisualSettings.graphicsSettingsActive()`;
                // Add binding for this setting
                if (Array.isArray(selector)) {
                    // For binding multiple elements at once, which requires more complicated selecting
                    selector.forEach(([query, order], i) => {
                        const elem = selectorWorkaround(container, query);
                        const commentBinding = i % 2 == 0 ? binding : '/ko';
                        if (order == 'before') {
                            elem.before(new Comment(commentBinding));
                        } else {
                            elem.after(new Comment(commentBinding));
                        }
                    });
                } else {
                    const elem = selectorWorkaround(container, selector);
                    // Special case: insert a backup attack-disabled element so formatting doesn't look weird
                    // Do this before applying the main binding to put it outside the binding comments
                    if (setting == 'attack') {
                        const replacementAttack = document.createElement('span');
                        elem.after(replacementAttack);
                        replacementAttack.outerHTML = `<span style="display: inline;" data-bind="${binding.replace('ko ifnot:', 'if:')}">Pokémon Attack: <span>-----</span></span>`;
                    }
                    // Insert the binding
                    elem.before(new Comment(binding));
                    elem.after(new Comment('/ko'));
                }
            });
        });
    }


    static addOptimizeVitamins() {
        // Add button to vitamin menu
        // (must execute before game loads and applies knockout bindings)
        const btn = document.createElement('button');
        btn.setAttribute('class', 'btn btn-link btn-sm text-decoration-none align-text-top');
        btn.setAttribute('style', 'line-height: 0.6; font-size: 1rem; float: right;');
        btn.setAttribute('data-bind', `click: () => { if ($data) { $data.optimizeVitamins() } }, class: (!$data.breeding ? 'text-success' : 'text-muted')`);
        btn.innerHTML = '⚖';
        document.querySelector('#pokemonVitaminExpandedModal tbody[data-bind*="PartyController.getVitaminSortedList"] td').appendChild(btn);

        // Add optimize-vitamin functions for party pokemon (adapted from wiki)
        PartyPokemon.prototype.calcBreedingEfficiency = function(vitaminsUsed) {
            // attack bonus
            const attackBonusPercent = (GameConstants.BREEDING_ATTACK_BONUS + vitaminsUsed[GameConstants.VitaminType.Calcium]) / 100;
            const proteinBoost = vitaminsUsed[GameConstants.VitaminType.Protein];
            const breedingAttackBonus = (this.baseAttack * attackBonusPercent) + proteinBoost;
            // egg steps
            const div = 300;
            const extraCycles = (vitaminsUsed[GameConstants.VitaminType.Calcium] + vitaminsUsed[GameConstants.VitaminType.Protein]) / 2;
            const steps = (this.eggCycles + extraCycles) * GameConstants.EGG_CYCLE_MULTIPLIER;
            const adjustedSteps = (steps <= div ? steps : Math.round(((steps / div) ** (1 - vitaminsUsed[GameConstants.VitaminType.Carbos] / 70)) * div));
            // efficiency
            return (breedingAttackBonus / adjustedSteps) * GameConstants.EGG_CYCLE_MULTIPLIER;
        }

        PartyPokemon.prototype.optimizeVitamins = function() {
            const totalVitamins = (player.highestRegion() + 1) * 5;
            const carbosUnlocked = player.highestRegion() >= GameConstants.Region.unova;
            const calciumUnlocked = player.highestRegion() >= GameConstants.Region.hoenn;
            const prices = GameHelper.enumStrings(GameConstants.VitaminType).map(v => ItemList[v].basePrice);
            // Add our initial starting efficiency here
            let optimalVitamins = [0, 0, 0];
            let eff = this.calcBreedingEfficiency(optimalVitamins);
            // Check all max-vitamin combinations
            for (let carbos = carbosUnlocked * totalVitamins; carbos >= 0; carbos--) {
                for (let calcium = calciumUnlocked * (totalVitamins - carbos); calcium >= 0; calcium--) {
                    let protein = totalVitamins - (carbos + calcium);
                    let newEff = this.calcBreedingEfficiency([protein, calcium, carbos]);
                    if (newEff >= eff) {
                        const newVitamins = [protein, calcium, carbos];
                        if (newEff == eff) {
                            // Choose cheaper version
                            const oldPrice = optimalVitamins.reduce((sum, v, i) => (sum + v * prices[i]), 0);
                            const newPrice = newVitamins.reduce((sum, v, i) => (sum + v * prices[i]), 0);
                            if (oldPrice <= newPrice) {
                               continue;
                            }
                        }
                        eff = newEff;
                        optimalVitamins = newVitamins;
                    }
                }
            }
            // Optimally use vitamins
            GameHelper.enumNumbers(GameConstants.VitaminType).forEach((v) => {
                if (this.vitaminsUsed[v]()) {
                    this.removeVitamin(v, Infinity);
                }
            });
            GameHelper.enumNumbers(GameConstants.VitaminType).forEach((v) => {
                if (v < optimalVitamins.length && optimalVitamins[v] > 0) {
                    this.useVitamin(v, optimalVitamins[v]);
                }
            });
        }
    }
}


/**
 * Creates container for scripts settings in the settings menu, adding scripts tab if it doesn't exist yet
 */
function createScriptSettingsContainer(name) {
    const settingsID = name.replaceAll(/s/g, '').toLowerCase();
    var settingsContainer = document.getElementById('settings-scripts-container');

    // Create scripts settings tab if it doesn't exist yet
    if (!settingsContainer) {
        // Fixes the Scripts nav item getting wrapped to the bottom by increasing the max width of the window
        document.querySelector('#settingsModal div').style.maxWidth = '850px';
        // Create and attach script settings tab link
        const settingTabs = document.querySelector('#settingsModal ul.nav-tabs');
        const li = document.createElement('li');
        li.classList.add('nav-item');
        li.innerHTML = `<a class="nav-link" href="#settings-scripts" data-toggle="tab">Scripts</a>`;
        settingTabs.appendChild(li);
        // Create and attach script settings tab contents
        const tabContent = document.querySelector('#settingsModal .tab-content');
        scriptSettings = document.createElement('div');
        scriptSettings.classList.add('tab-pane');
        scriptSettings.setAttribute('id', 'settings-scripts');
        tabContent.appendChild(scriptSettings);
        settingsContainer = document.createElement('div');
        settingsContainer.setAttribute('id', 'settings-scripts-container');
        scriptSettings.appendChild(settingsContainer);
    }

    // Create settings container
    const settingsTable = document.createElement('table');
    settingsTable.classList.add('table', 'table-striped', 'table-hover', 'm-0');
    const header = document.createElement('thead');
    header.innerHTML = `<tr><th colspan="2">${name}</th></tr>`;
    settingsTable.appendChild(header);
    const settingsBody = document.createElement('tbody');
    settingsBody.setAttribute('id', `settings-scripts-${settingsID}`);
    settingsTable.appendChild(settingsBody);

    // Insert settings container in alphabetical order
    let settingsList = Array.from(settingsContainer.children);
    let insertBefore = settingsList.find(elem => elem.querySelector('tbody').id > `settings-scripts-${settingsID}`);
    if (insertBefore) {
        insertBefore.before(settingsTable);
    } else {
        settingsContainer.appendChild(settingsTable);
    }

    return settingsBody;
}

function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

function loadEpheniaScript(scriptName, initFunction, priorityFunction) {
    function reportScriptError(scriptName, error) {
        console.error(`Error while initializing '${scriptName}' userscript:\n${error}`);
        Notifier.notify({
            type: NotificationConstants.NotificationOption.warning,
            title: scriptName,
            message: `The '${scriptName}' userscript crashed while loading. Check for updates or disable the script, then restart the game.\n\nReport script issues to the script developer, not to the Pokéclicker team.`,
            timeout: GameConstants.DAY,
        });
    }
    const windowObject = !App.isUsingClient ? unsafeWindow : window;
    // Inject handlers if they don't exist yet
    if (windowObject.epheniaScriptInitializers === undefined) {
        windowObject.epheniaScriptInitializers = {};
        const oldInit = Preload.hideSplashScreen;
        var hasInitialized = false;

        // Initializes scripts once enough of the game has loaded
        Preload.hideSplashScreen = function (...args) {
            var result = oldInit.apply(this, args);
            if (App.game && !hasInitialized) {
                // Initialize all attached userscripts
                Object.entries(windowObject.epheniaScriptInitializers).forEach(([scriptName, initFunction]) => {
                    try {
                        initFunction();
                    } catch (e) {
                        reportScriptError(scriptName, e);
                    }
                });
                hasInitialized = true;
            }
            return result;
        }
    }

    // Prevent issues with duplicate script names
    if (windowObject.epheniaScriptInitializers[scriptName] !== undefined) {
        console.warn(`Duplicate '${scriptName}' userscripts found!`);
        Notifier.notify({
            type: NotificationConstants.NotificationOption.warning,
            title: scriptName,
            message: `Duplicate '${scriptName}' userscripts detected. This could cause unpredictable behavior and is not recommended.`,
            timeout: GameConstants.DAY,
        });
        let number = 2;
        while (windowObject.epheniaScriptInitializers[`${scriptName} ${number}`] !== undefined) {
            number++;
        }
        scriptName = `${scriptName} ${number}`;
    }
    // Add initializer for this particular script
    windowObject.epheniaScriptInitializers[scriptName] = initFunction;
    // Run any functions that need to execute before the game starts
    if (priorityFunction) {
        $(document).ready(() => {
            try {
                priorityFunction();
            } catch (e) {
                reportScriptError(scriptName, e);
                // Remove main initialization function  
                windowObject.epheniaScriptInitializers[scriptName] = () => null;
            }
        });
    }
}

if (!App.isUsingClient || localStorage.getItem('additionalvisualsettings') === 'true') {
    if (!App.isUsingClient) {
        // Necessary for userscript managers
        unsafeWindow.AdditionalVisualSettings = AdditionalVisualSettings;
    }
    loadEpheniaScript('additionalvisualsettings', () => AdditionalVisualSettings.initVisualSettings(), () => AdditionalVisualSettings.initOnLoad());
}