Greasy Fork is available in English.

FlatMMO Bank Value

Shows total vendor sale value of bank items

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==UserScript==
// @name         FlatMMO Bank Value
// @version      0.1
// @description  Shows total vendor sale value of bank items
// @author       chillora
// @license      MIT
// @match        *://flatmmo.com/play.php*
// @grant        none
// @require      https://update.greatest.deepsurf.us/scripts/544062/FlatMMOPlus.js
// @namespace https://greatest.deepsurf.us/users/1600821
// ==/UserScript==

(function() {
    'use strict';

    class BankValuePlugin extends FlatMMOPlusPlugin {
        constructor() {
            super("bankValue", {
                about: {
                    name: GM_info.script.name,
                    version: GM_info.script.version,
                    author: GM_info.script.author,
                    description: GM_info.script.description
                }
            });
            this.prices = {};
        }

        async onLogin() {
            const res = await fetch("https://flatmmo.com/data/prices.php");
            const text = await res.text();
            text.split("<br />").forEach(line => {
                const [price, item] = line.split(" - ");
                if (item) this.prices[item.trim()] = parseInt(price) || 0;
            });
            console.log("[BankValue] Loaded", Object.keys(this.prices).length, "prices");
            this.watchBank();
        }

        watchBank() {
            const self = this;
            const storage = document.getElementById("storage");
            if (!storage) return;

            let timeout = null;
            const update = () => {
                if (timeout) return;
                timeout = setTimeout(() => {
                    timeout = null;
                    const isOpen = storage.style.display !== "none";
                    const el = document.getElementById("bank-value-display");
                    if (isOpen) {
                        if (!el) self.insertValue(storage);
                        else el.textContent = `Bank Value: ${self.calcTotal().toLocaleString()} coins`;
                    } else if (el) {
                        el.remove();
                    }
                }, 150);
            };
            new MutationObserver(update).observe(storage, { childList: true, subtree: true, attributes: true, attributeFilter: ["style"] });
        }

        calcTotal() {
            let total = 0;
            document.querySelectorAll("[data-bank-item-name]").forEach(el => {
                const name = el.getAttribute("data-bank-item-name");
                const img = el.querySelector("img[onclick]");
                if (img) {
                    const match = img.getAttribute("onclick").match(/,\s*["'](\d+)["']\s*\)/);
                    const qty = match ? parseInt(match[1]) : 0;
                    const price = this.prices[name] || 0;
                    total += qty * price;
                }
            });
            return total;
        }

        insertValue(storage) {
            const el = document.createElement("span");
            el.id = "bank-value-display";
            el.style.cssText = "color:#ffd700;font-weight:bold;font-size:14px;margin-left:15px;vertical-align:middle;";
            el.textContent = `Bank Value: ${this.calcTotal().toLocaleString()} coins`;
            const searchInput = storage.querySelector("#text-search-bank-input");
            if (searchInput) searchInput.after(el);
        }
    }

    FlatMMOPlus.registerPlugin(new BankValuePlugin());
})();