FlatMMO Bank Value

Shows total vendor sale value of bank items

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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());
})();