aboutsummaryrefslogtreecommitdiff
path: root/static/js/script.js
diff options
context:
space:
mode:
authorBobby <[email protected]>2023-04-06 07:34:23 +0000
committerBobby <[email protected]>2023-04-06 07:34:23 +0000
commitc4e3cfc22ec8d3476b58b3211815571f7e61b67f (patch)
treebe7e308976b66926c1d8d967aab2398fef0f58ef /static/js/script.js
parentd16738a28014408ddcc9ded0d7f5d4d2f1682eed (diff)
downloadffxivmfp-c4e3cfc22ec8d3476b58b3211815571f7e61b67f.tar.xz
ffxivmfp-c4e3cfc22ec8d3476b58b3211815571f7e61b67f.zip
Update interface with better table layout
Diffstat (limited to 'static/js/script.js')
-rw-r--r--static/js/script.js45
1 files changed, 37 insertions, 8 deletions
diff --git a/static/js/script.js b/static/js/script.js
index 9c4cc0e..caf78d1 100644
--- a/static/js/script.js
+++ b/static/js/script.js
@@ -11,7 +11,9 @@ function commaSeparateNumber(val) {
numInputs.forEach((input) => {
input.addEventListener("keyup", (e) => {
- const num = e.target.value.replace(/\D/g, "");
+ const value = e.target.value;
+ const formattedValue = commaSeparateNumber(value.replace(/\D/g, ""));
+ e.target.value = formattedValue;
});
});
@@ -22,15 +24,42 @@ calculateForm.addEventListener("submit", (e) => {
const reducedTaxes = document.getElementById("taxrates");
const buyTaxRate = 0.05;
const sellTaxRate = reducedTaxes.checked ? 0.03 : 0.05;
- const buyPriceValue = buyPrice.value.replace(/\D/g, "");
- const sellPriceValue = sellPrice.value.replace(/\D/g, "");
+ const buyPriceValue = parseInt(buyPrice.value.replace(/\D/g, ""));
+ const sellPriceValue = parseInt(sellPrice.value.replace(/\D/g, ""));
const buyTax = Math.ceil(buyPriceValue * buyTaxRate);
const sellTax = Math.ceil(sellPriceValue * sellTaxRate);
const profit = sellPriceValue - buyPriceValue - buyTax - sellTax;
-
- const resultStatement = `For an item listed at ${commaSeparateNumber(buyPriceValue)} Gil, you will pay ${commaSeparateNumber(buyTax)} Gil in taxes. If you sell the item for ${commaSeparateNumber(sellPriceValue)} Gil, you will pay ${commaSeparateNumber(sellTax)} Gil in taxes. After all taxes are paid, you will ${profit > 0 ? "<span class='profit'>make a profit</span>" : "<span class='loss'>suffer a loss</span>"} of ${commaSeparateNumber(Math.abs(profit))} Gil.`;
- const statementElement = document.createElement("p");
- statementElement.innerHTML = resultStatement;
+ const timesProfit = profit / (buyPriceValue + buyTax);
+
+ const resultDisplay = `
+ <table class="result-display">
+ <tr>
+ <td>Buying Cost:</td>
+ <td>${commaSeparateNumber(buyPriceValue)} Gil</td>
+ </tr>
+ <tr>
+ <td>Buying Tax:</td>
+ <td>${commaSeparateNumber(buyTax)} Gil</td>
+ </tr>
+ <tr>
+ <td>Selling Cost:</td>
+ <td>${commaSeparateNumber(sellPriceValue)} Gil</td>
+ </tr>
+ <tr>
+ <td>Selling Tax:</td>
+ <td>${commaSeparateNumber(sellTax)} Gil</td>
+ </tr>
+ <tr>
+ <td>${profit > 0 ? "Profit" : "Loss"}:</td>
+ <td><span class="${profit > 0 ? "profit" : "loss"}">${commaSeparateNumber(Math.abs(profit))}</span> Gil
+ ${profit > 0 ? `(${timesProfit.toFixed(2)}x returns)` : `(${timesProfit.toFixed(2)}x loss)`}</td>
+ </td>
+ </tr>
+ </table>
+ `;
+
+ const resultElement = document.createElement("div");
+ resultElement.innerHTML = resultDisplay;
result.innerHTML = "";
- result.appendChild(statementElement);
+ result.appendChild(resultElement);
});