IdlePixel UI Tweaks

Adds some options to change details about the IdlePixel user interface.

20.03.2022 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         IdlePixel UI Tweaks
// @namespace    com.anwinity.idlepixel
// @version      1.0.4
// @description  Adds some options to change details about the IdlePixel user interface.
// @author       Anwinity
// @license      MIT
// @match        https://idle-pixel.com/play.php*
// @grant        none
// @require      https://greasyfork.org/scripts/441206-idlepixel/code/IdlePixel+.js?version=1030265
// ==/UserScript==

(function() {
    'use strict';

    const FONTS = [];
    const FONT_DEFAULT = "IdlePixel Default";
    const FONT_FAMILY_DEFAULT = "pixel, \"Courier New\", Courier, monospace";
    (async() => {
        const FONTS_CHECK = new Set([
            // Windows 10
            'Arial', 'Arial Black', 'Bahnschrift', 'Calibri', 'Cambria', 'Cambria Math', 'Candara', 'Comic Sans MS', 'Consolas', 'Constantia', 'Corbel', 'Courier New', 'Ebrima', 'Franklin Gothic Medium', 'Gabriola', 'Gadugi', 'Georgia', 'HoloLens MDL2 Assets', 'Impact', 'Ink Free', 'Javanese Text', 'Leelawadee UI', 'Lucida Console', 'Lucida Sans Unicode', 'Malgun Gothic', 'Marlett', 'Microsoft Himalaya', 'Microsoft JhengHei', 'Microsoft New Tai Lue', 'Microsoft PhagsPa', 'Microsoft Sans Serif', 'Microsoft Tai Le', 'Microsoft YaHei', 'Microsoft Yi Baiti', 'MingLiU-ExtB', 'Mongolian Baiti', 'MS Gothic', 'MV Boli', 'Myanmar Text', 'Nirmala UI', 'Palatino Linotype', 'Segoe MDL2 Assets', 'Segoe Print', 'Segoe Script', 'Segoe UI', 'Segoe UI Historic', 'Segoe UI Emoji', 'Segoe UI Symbol', 'SimSun', 'Sitka', 'Sylfaen', 'Symbol', 'Tahoma', 'Times New Roman', 'Trebuchet MS', 'Verdana', 'Webdings', 'Wingdings', 'Yu Gothic',
            // macOS
            'American Typewriter', 'Andale Mono', 'Arial', 'Arial Black', 'Arial Narrow', 'Arial Rounded MT Bold', 'Arial Unicode MS', 'Avenir', 'Avenir Next', 'Avenir Next Condensed', 'Baskerville', 'Big Caslon', 'Bodoni 72', 'Bodoni 72 Oldstyle', 'Bodoni 72 Smallcaps', 'Bradley Hand', 'Brush Script MT', 'Chalkboard', 'Chalkboard SE', 'Chalkduster', 'Charter', 'Cochin', 'Comic Sans MS', 'Copperplate', 'Courier', 'Courier New', 'Didot', 'DIN Alternate', 'DIN Condensed', 'Futura', 'Geneva', 'Georgia', 'Gill Sans', 'Helvetica', 'Helvetica Neue', 'Herculanum', 'Hoefler Text', 'Impact', 'Lucida Grande', 'Luminari', 'Marker Felt', 'Menlo', 'Microsoft Sans Serif', 'Monaco', 'Noteworthy', 'Optima', 'Palatino', 'Papyrus', 'Phosphate', 'Rockwell', 'Savoye LET', 'SignPainter', 'Skia', 'Snell Roundhand', 'Tahoma', 'Times', 'Times New Roman', 'Trattatello', 'Trebuchet MS', 'Verdana', 'Zapfino',
            // other
            'Helvetica', 'Garamond',
        ].sort());
        await document.fonts.ready;
        for(const font of FONTS_CHECK.values()) {
            if (document.fonts.check(`12px "${font}"`)) {
                FONTS.push(font);
            }
        }
        FONTS.unshift("IdlePixel Default");
    })();

    class UITweaksPlugin extends IdlePixelPlusPlugin {
        constructor() {
            super("ui-tweaks", {
                about: {
                    name: GM_info.script.name,
                    version: GM_info.script.version,
                    author: GM_info.script.author,
                    description: GM_info.script.description
                },
                config: [
                    {
                        id: "font",
                        label: "Primary Font",
                        type: "select",
                        options: FONTS,
                        default: FONT_DEFAULT
                    },
                    /*{
                        id: "menuflex",
                        label: "Menu FlexBox",
                        type: "boolean",
                        default: true
                    }*/
                ]
            });
        }

        onConfigsChanged() {
            const font = this.getConfig("font");
            if(!font || font==FONT_DEFAULT) {
                $("body").css("font-family", "");
            }
            else {
                $("body").css("font-family", font);
            }

            /* // latest ui changes broke this, need to rethink it
            if(IdlePixelPlus.getVar("username")) { // only run this once logged in
                const menuflex = this.getConfig("menuflex");
                const gameScreen = $("#game-screen");
                const menuBar = $("#game-screen > .menu-bar");
                const panelsDiv = $("#panels");

                if(menuflex) {


                    gameScreen.css("display", "flex");
                    gameScreen.css("flex-direction", "row");
                    menuBar.css("flex-grow", "0");
                    menuBar.css("min-width", "250px");
                    menuBar.css("height", "100vh");
                    panelsDiv.css("flex-grow", "1");

                }
                else {


                    gameScreen.css("display", "");
                    gameScreen.css("flex-direction", "");
                    menuBar.css("flex-grow", "");
                    menuBar.css("min-width", "");
                    menuBar.css("height", "");
                    panelsDiv.css("flex-grow", "");

                }
            }
            */
        }

        onLogin() {
            this.onConfigsChanged();
        }

        onPanelChanged(panelBefore, panelAfter) {
            if(panelBefore != panelAfter && panelAfter == "idlepixelplus") {
                const options = $("#idlepixelplus-config-ui-tweaks-font > option");
                if(options) {
                    options.each(function() {
                        const el = $(this);
                        let value = el.attr("value");
                        if(value == "IdlePixel Default") {
                            el.css("font-family", FONT_FAMILY_DEFAULT);
                        }
                        else {
                            el.css("font-family", value);
                        }
                    });
                }
            }
        }

    }

    const plugin = new UITweaksPlugin();
    IdlePixelPlus.registerPlugin(plugin);

})();