IdlePixel UI Tweaks

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

目前為 2022-09-01 提交的版本,檢視 最新版本

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

(function() {
    'use strict';

    const LEVELS = function(){
        let result = [];
        result[1] = 0;
        for(let lv = 2; lv <= 100; lv++) {
            result[lv] = Math.ceil(Math.pow(lv, 3+(lv/200)));
        }
        return result;
    }();

    function xpToLevel(xp) {
        if(xp <= 0) {
            return 1;
        }
        if(xp >= LEVELS[100]) {
            return 100;
        }
        let lower = 1;
        let upper = 100;
        while(lower <= upper) {
            let mid = Math.floor((lower + upper) / 2);
            let midXP = LEVELS[mid];
            let midPlus1XP = LEVELS[mid+1];
            if(xp < midXP) {
                upper = mid;
                continue;
            }
            if(xp > midPlus1XP) {
                lower=mid+1;
                continue;
            }
            if(mid<100 && xp == LEVELS[mid+1]) {
                return mid+1;
            }
            return mid;
        }
    }

    const IMAGE_URL_BASE = $("itembox[data-item=copper] img").attr("src").replace(/\/[^/]+.png$/, "");
    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");
    })();

    const COLORS = {
        "body": 'rgb(200, 247, 248)',
        ".top-bar": $(".top-bar").css("background-color"),
        "#menu-bar": $("#menu-bar").css("background-color"),
        "#chat-area": $("#chat-area").css("background-color"),
        "#game-chat": $("#game-chat").css("background-color")
    };

    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: [
                    {
                        label: "General Stuff",
                        type: "label"
                    },
                    {
                        id: "font",
                        label: "Primary Font",
                        type: "select",
                        options: FONTS,
                        default: FONT_DEFAULT
                    },
                    {
                        id: "sideChat",
                        label: "Side Chat",
                        type: "boolean",
                        default: false
                    },
                    {
                        id: "fightPointsStats",
                        label: "FP Stats",
                        type: "boolean",
                        default: true
                    },
                    {
                        label: "Color Overrides",
                        type: "label"
                    },
                    {
                        id: "color-enabled-body",
                        label: "Main Background: Enabled",
                        type: "boolean",
                        default: false
                    },
                    {
                        id: "color-body",
                        label: "Main Background: Color",
                        type: "color",
                        default: COLORS["body"]
                    },
                    {
                        id: "color-enabled-top-bar",
                        label: "Top Background: Enabled",
                        type: "boolean",
                        default: false
                    },
                    {
                        id: "color-top-bar",
                        label: "Top Background: Color",
                        type: "color",
                        default: COLORS[".top-bar"]
                    },
                    {
                        id: "color-enabled-menu-bar",
                        label: "Menu Background: Enabled",
                        type: "boolean",
                        default: false
                    },
                    {
                        id: "color-menu-bar",
                        label: "Menu Background: Color",
                        type: "color",
                        default: COLORS["#menu-bar"]
                    },
                    {
                        id: "color-enabled-chat-area",
                        label: "Inner Chat BG: Enabled",
                        type: "boolean",
                        default: false
                    },
                    {
                        id: "color-chat-area",
                        label: "Inner Chat BG: Color",
                        type: "color",
                        default: COLORS["#chat-area"]
                    },
                    {
                        id: "color-enabled-game-chat",
                        label: "Outer Chat BG: Enabled",
                        type: "boolean",
                        default: false
                    },
                    {
                        id: "color-game-chat",
                        label: "Outer Chat BG: Color",
                        type: "color",
                        default: COLORS["#game-chat"]
                    }
                ]
            });
        }

        onConfigsChanged() {
            $("body").css("font-family", "");
            const font = this.getConfig("font");
            if(font && font!=FONT_DEFAULT) {
                const bodyStyle = $("body").attr("style");
                $("body").attr("style", `${bodyStyle}; font-family: ${font} !important`);
            }

            const sideChat = this.getConfig("sideChat");
            if(sideChat) {
                $("#content").addClass("side-chat");
            }
            else {
                $("#content").removeClass("side-chat");
            }

            Object.keys(COLORS).forEach(selector => {
                const key = selector.replace(/[#\.]/g, '');
                const enabled = this.getConfig(`color-enabled-${key}`);
                const color = enabled ? this.getConfig(`color-${key}`) : COLORS[selector];
                // console.log(`COLOR: [${enabled}] '${selector}' -> '${color}'`);
                $(selector).css("background-color", color);
            });

            if(this.getConfig("fightPointsStats")) {
                $("#menu-bar-fight-points").show();
            }
            else {
                $("#menu-bar-fight-points").hide();
            }

        }

        onLogin() {
            // fix chat
            const chat = $("#game-chat > :first-child");
            const chatTop = $('<div id="chat-top"></div>"');
            const chatArea = $("#chat-area").detach();
            const chatBottom = $("#game-chat > :first-child > :last-child").detach();
            $("#game-chat > :first-child > *").detach().appendTo(chatTop);
            chat.empty();
            chat.append(chatTop);
            chat.append(chatArea);
            chat.append(chatBottom);

            this.onConfigsChanged();
            $("head").append(`
            <style id="styles-ui-tweaks">
            #chat-top {
              display: flex;
              flex-direction: row;
              justify-content: left;
            }
            #chat-top > button {
              margin-left: 2px;
              margin-right: 2px;
              white-space: nowrap;
            }
            #content.side-chat {
              display: grid;
              column-gap: 0;
              row-gap: 0;
              grid-template-columns: 2fr minmax(300px, 1fr);
              grid-template-rows: 1fr;
            }
            #content.side-chat #game-chat {
              max-height: calc(100vh - 32px);
            }
            #content.side-chat #game-chat > :first-child {
              display: grid;
              column-gap: 0;
              row-gap: 0;
              grid-template-columns: 1fr;
              grid-template-rows: auto 1fr auto;
              height: calc(100% - 16px);
            }
            #content.side-chat #chat-area {
              height: auto !important;
            }
            </style>
            `);

            $("#menu-bar-energy").after(`
            <span id="menu-bar-fight-points">
              <br />
              <img id="menu-bar-fight-points-img" class="img-20" src="${IMAGE_URL_BASE}/fight_points.png"> <item-display data-format="number" data-key="fight_points">0</item-display>
            </span>
            `);

            $(".color-grey.font-small item-display").each(function() {
                let el = $(this);
                let dataKey = el.attr("data-key");
                if(dataKey.endsWith("_xp")) {
                    el.after(`
                    <span class="ui-tweaks-xp-next">
                      &nbsp;&nbsp;Next Level:
                      <item-display data-format="number"data-key="ipp_${dataKey}_next"></item-display>
                    </span>
				    `);
                }
            });


            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);
                        }
                    });
                }
            }
        }

        onVariableSet(key, valueBefore, valueAfter) {
            if(key.endsWith("_xp")) {
                const varName = `var_ipp_${key}_next`;
                const xp = parseInt(valueAfter||'0');
                const level = xpToLevel(xp);
                const xpAtNext = LEVELS[level+1];
                const next = level>=100 ? 0 : xpAtNext-xp;
                window[varName] = `${next}`;
            }
        }

    }

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

})();

QingJ © 2025

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