FlatMMO Bank Value

Shows total vendor sale value of bank items

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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