FlatMMO Bank Value

Shows total vendor sale value of bank items

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

(I already have a user style manager, let me install it!)

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