Widget:Calculator/Magic/Aurum: Difference between revisions

From HighSpell Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(25 intermediate revisions by the same user not shown)
Line 1: Line 1:
<html>
<html>
<form id="aurum-controls">
<form id="aurum-controls" class="form-grid">
   Scroll Price: <input type="number" id="scrollPrice" value="100"><br>
   <label>
   Quantity: <input type="number" id="quantity" value="1"><br>
    <span><a href="/w/Alchemy_Scroll" title="Alchemy Scroll">Alchemy Scroll</a> Price:</span>
    <input type="number" id="scrollPrice" value="350" min="1" max="1000">
  </label>
   <label>
    <span>Quantity:</span>
    <input type="number" id="quantity" value="1" min="1" max="99999">
  </label>
</form>
</form>
<script>
function calculateProfits() {
  const coinIcon = ' <span class="noviewer" typeof="mw:File"><span><img src="/w/images/thumb/9/9a/Coins_icon.png/16px-Coins_icon.png" decoding="async" width="16" height="16" class="mw-file-element" srcset="/w/images/thumb/9/9a/Coins_icon.png/24px-Coins_icon.png 1.5x, /w/images/9/9a/Coins_icon.png 2x"></span></span>';


<table id="aurum-table" border="1">
   // Scroll Price
   <thead>
  const scrollInput = document.getElementById('scrollPrice');
    <tr>
   let scrollPrice = parseFloat(scrollInput.value);
      <th>Item</th>
   if (isNaN(scrollPrice) || scrollPrice < 0) {
      <th>Buy Price</th>
     scrollPrice = 1;
      <th>Minor Profit</th>
     scrollInput.value = 1;
      <th>Major Profit</th>
   }
      <th>Total Profit (qty)</th>
    </tr>
   </thead>
   <tbody>
     <tr data-buyprice="500">
      <td>Item A</td>
      <td>500</td>
      <td class="minorProfit"></td>
      <td class="majorProfit"></td>
      <td class="totalProfit"></td>
     </tr>
    <tr data-buyprice="1200">
      <td>Item B</td>
      <td>1200</td>
      <td class="minorProfit"></td>
      <td class="majorProfit"></td>
      <td class="totalProfit"></td>
    </tr>
   </tbody>
</table>


<script>
  // Quantity
function calculateProfits() {
   const quantityInput = document.getElementById('quantity');
   const scrollPrice = parseFloat(document.getElementById('scrollPrice').value);
   let quantity = parseInt(quantityInput.value);
   const quantity = parseInt(document.getElementById('quantity').value);
  if (isNaN(quantity) || quantity < 1) {
    quantity = 1;
    quantityInput.value = 1;
  }


   document.querySelectorAll('#aurum-table tbody tr').forEach(row => {
   document.querySelectorAll('#aurum-table tbody tr').forEach(row => {
     const buyPrice = parseFloat(row.dataset.buyprice);
     const aurumMinorValue = parseInt(row.dataset.aurumMinor);
      
     const aurumMajorValue = parseInt(row.dataset.aurumMajor);
     const minorProfit = 1500 - buyPrice - scrollPrice;
 
     const majorProfit = 3000 - buyPrice - (scrollPrice * 3);
     const aurumMinor = isNaN(aurumMinorValue) ? 0 : aurumMinorValue - scrollPrice;
     const totalProfit = (majorProfit * quantity); // you could switch to minor here
     const aurumMajor = isNaN(aurumMajorValue) ? 0 : aurumMajorValue - scrollPrice;
      
 
     row.querySelector('.minorProfit').textContent = minorProfit.toFixed(2);
    const minorTotal = aurumMinor * quantity;
     row.querySelector('.majorProfit').textContent = majorProfit.toFixed(2);
     const majorTotal = aurumMajor * quantity;
     row.querySelector('.totalProfit').textContent = totalProfit.toFixed(2);
 
    function wrap(value) {
      const formatted = value.toLocaleString("en-US");
      return value < 0
        ? `<span style="color:#ee4231 !important">${formatted}</span> ${coinIcon}`
        : `${formatted} ${coinIcon}`;
     }
 
     row.querySelector('.aurumMinorEach').innerHTML = wrap(aurumMinor);
    row.querySelector('.aurumMajorEach').innerHTML = wrap(aurumMajor);
     row.querySelector('.aurumMinorTotal').innerHTML = wrap(minorTotal);
     row.querySelector('.aurumMajorTotal').innerHTML = wrap(majorTotal);
   });
   });
}
}
Line 53: Line 56:
document.getElementById('scrollPrice').addEventListener('input', calculateProfits);
document.getElementById('scrollPrice').addEventListener('input', calculateProfits);
document.getElementById('quantity').addEventListener('input', calculateProfits);
document.getElementById('quantity').addEventListener('input', calculateProfits);
 
document.addEventListener('DOMContentLoaded', calculateProfits);
calculateProfits(); // Initial call
</script>
</script>
</html>
</html>

Latest revision as of 15:57, 26 June 2025