Greasy Fork

Greasy Fork is available in English.

Real Profit Calculator

Calculates and displays real profit from given page values without duplication

当前为 2025-05-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Real Profit Calculator
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Calculates and displays real profit from given page values without duplication
// @author       guch8017
// @match        https://shykai.github.io/MWICombatSimulatorTest/dist/
// @grant        GM_registerMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    GM_registerMenuCommand("设置社区掉落增益", async function () {
        const currentRate = await GM_getValue('buffRate', 1.295);
        const input = prompt("Enter new Buff Rate:", currentRate);
        if (input !== null) {
            const parsed = parseFloat(input);
            if (!isNaN(parsed) && parsed > 0) {
                await GM_setValue('buffRate', parsed);
                alert(`Buff rate set to ${parsed}. Reload the page to see changes.`);
            } else {
                alert("Invalid input. Please enter a positive number.");
            }
        }
    });

    function waitForElement(selector, callback) {
        const observer = new MutationObserver(() => {
            const el = document.querySelector(selector);
            if (el) {
                observer.disconnect();
                callback(el);
            }
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }

    function parseNumber(text) {
        const numericText = text.replace(/[^\d.,\-]/g, '').replace(/,/g, '');
        return parseFloat(numericText);
    }

    async function calculateAndInsert() {
        const expenseText = document.getElementById('script_expense')?.textContent || '';
        const noRngProfitText = document.getElementById('noRngProfitPreview')?.textContent || '';

        const expense = parseNumber(expenseText);
        const noRngProfit = parseNumber(noRngProfitText);
        const buffRate = await GM_getValue('buffRate', 1.295);

        if (!isNaN(expense) && !isNaN(noRngProfit)) {
            const realProfit = ((noRngProfit + expense) * 1.295) - expense;
            const formattedProfit = realProfit.toLocaleString(undefined, { maximumFractionDigits: 3 });

            const existingDiv = document.getElementById('realProfitDisplay');
            if (existingDiv) {
                existingDiv.textContent = `实际期望利润: ${formattedProfit}`;
                return;
            }

            const displayDiv = document.createElement('div');
            displayDiv.id = 'realProfitDisplay';
            displayDiv.style.backgroundColor = '#FFD700';
            displayDiv.style.color = 'black';
            displayDiv.style.fontWeight = 'bold';
            displayDiv.style.padding = '4px';
            displayDiv.textContent = `实际期望利润: ${formattedProfit}`;

            const targetDiv = document.getElementById('noRngProfitPreview').parentElement.parentElement;
            targetDiv.parentNode.insertBefore(displayDiv, targetDiv.nextSibling);
        }
    }

    waitForElement('#noRngProfitPreview', () => {
        calculateAndInsert();

        const config = { characterData: true, subtree: true, childList: true };

        const expenseNode = document.getElementById('script_expense');
        const profitNode = document.getElementById('noRngProfitPreview');

        const observer = new MutationObserver(calculateAndInsert);

        if (expenseNode) observer.observe(expenseNode, config);
        if (profitNode) observer.observe(profitNode, config);
    });
})();