IdlePixel Var Viewer

Easily view all game variables in a table.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         IdlePixel Var Viewer
// @namespace    com.anwinity.idlepixel
// @version      1.2.7
// @description  Easily view all game variables in a table.
// @author       Anwinity
// @license      MIT
// @match        *://idle-pixel.com/login/play*
// @grant        none
// @require      https://greatest.deepsurf.us/scripts/441206-idlepixel/code/IdlePixel+.js?anticache=20220905
// ==/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 = $(".game-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;
                    color: black;
                    background-color: white;
                }
                #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();
            }
            return false;
        }

        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)
                .filter(key => key.startsWith("var_"))
                .sort()
                .forEach(key => {
                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) {
                        let value = window[key] ?? "";
                        if(key == "var_animal_data") {
                            value = value.replace(/=/g, "=<br />");
                        }
                        content += `<tr><td>${key}</td><td>${value}</td></tr>`;
                    }
            });
            tbody.empty();
            tbody.append(content);
            return false;
        }

    }

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

})();