IdlePixel Var Viewer

Easily view all game variables in a table.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         IdlePixel Var Viewer
// @namespace    com.anwinity.idlepixel
// @version      1.2.1
// @description  Easily view all game variables in a table.
// @author       Anwinity
// @license      MIT
// @match        *://idle-pixel.com/login/play*
// @grant        none
// @require      https://greasyfork.org/scripts/441206-idlepixel/code/IdlePixel+.js
// ==/UserScript==

(function() {
    'use strict';

    class VarViewerPlugin extends IdlePixelPlusPlugin {
        constructor() {
            super("varviewer", {
                about: {
                    name: GM_info.script.name,
                    version: GM_info.script.version,
                    author: GM_info.script.author,
                    description: GM_info.script.description
                }
            });
        }

        onLogin() {
            const usernameElement = $("#menu-bar-buttons item-display[data-key=username]");
            const onlineCount = $(".top-bar .gold:not(#top-bar-admin-link)");
            onlineCount.before(`
            <a href="#" class="hover float-end link-no-decoration" onclick="event.preventDefault(); IdlePixelPlus.setPanel('varviewer')" title="Open VarViewer">Vars&nbsp;&nbsp;&nbsp;</a>
            `);

            IdlePixelPlus.addPanel("varviewer", "Var Viewer", function() {
                let content = `
                <style>
                #varviewer-table {
                    margin-top: 0.25em;
                }
                #varviewer-table, #varviewer-table tr, #varviewer-table th, #varviewer-table td {
                    border: 1px solid black;
                    font-family: 'Courier New', monospace;
                }
                #varviewer-table th, #varviewer-table td {
                    padding: 2px;
                }
                #varviewer-table td:last-child {
                    text-align: right;
                }
                </style>
                <input id="varviewer-filter" type="text" placeholder="text or /regex/" style="min-width: 250px" onkeyup="IdlePixelPlus.plugins.varviewer.onFilterKeyUp(event)" />
                <button onclick="IdlePixelPlus.plugins.varviewer.refilter()">Filter / Refresh</button>
                <br />
                <table id="varviewer-table">
                    <thead>
                        <tr>
                            <th>Key</th>
                            <th>Value</th>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
                `;
                return content;
            });
            IdlePixelPlus.refreshPanel("varviewer");
            this.refilter();
        }

        onFilterKeyUp(event) {
            if(event.keyCode === 13) {
                this.refilter();
            }
        }

        refilter() {
            const tbody = $("#varviewer-table tbody");
            const filter = ($("#varviewer-filter").val() || "").trim().toLowerCase();
            let regex = null;
            if(filter.startsWith("/") && filter.endsWith("/")) {
                try {
                    regex = new RegExp(filter.substring(1, filter.length-1), 'i');
                }
                catch(err) {

                }
            }
            let content = "";
            Object.keys(window).forEach(key => {
                if(key.startsWith("var_")) {
                    let show = false;
                    if(!filter) {
                        show = true;
                    }
                    else if(regex) {
                        const val = window[key];
                        if(regex.test(key) || regex.test(val)) {
                            show = true;
                        }
                    }
                    else {
                        const keyLower = key.toLowerCase();
                        const valLower = window[key].toLowerCase();
                        if(keyLower.includes(filter) || valLower.includes(filter)) {
                            show = true;
                        }
                    }

                    if(show) {
                        content += `<tr><td>${key}</td><td>${window[key]}</td></tr>`;
                    }
                }
            });
            tbody.empty();
            tbody.append(content);
        }

    }

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

})();