Greasy Fork is available in English.
Calculates and displays real profit from given page values without duplication
当前为
// ==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);
});
})();