FlatMMO Bank Value

Shows total vendor sale value of bank items

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

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