Widget:Calculator/Magic/Aurum: Difference between revisions

From HighSpell Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 4: Line 4:
   Quantity: <input type="number" id="quantity" value="1"><br>
   Quantity: <input type="number" id="quantity" value="1"><br>
</form>
</form>
<script>
<script>
function calculateProfits() {
function calculateProfits() {
   const scrollPrice = parseFloat(document.getElementById('scrollPrice').value);
   const scrollPrice = parseFloat(document.getElementById('scrollPrice').value) || 0;
   const quantity = parseInt(document.getElementById('quantity').value);
   const quantity = parseInt(document.getElementById('quantity').value) || 1;


   document.querySelectorAll('#aurum-table tbody tr').forEach(row => {
   document.querySelectorAll('#aurum-table tbody tr').forEach(row => {
Line 13: Line 14:
     if (isNaN(itemPrice)) return;
     if (isNaN(itemPrice)) return;


     // Correct value logic
     // Each values
     const minorValue = itemPrice * 0.0375;
     const minorEach = Math.round(itemPrice * 0.0375);
     const majorValue = itemPrice * 0.5;
     const majorEach = Math.round(itemPrice * 0.5);


     const minorProfit = Math.round(minorValue - scrollPrice);
    // Profit after scroll cost × quantity
     const majorProfit = Math.round(majorValue - scrollPrice);
     const minorTotal = Math.round((minorEach - scrollPrice) * quantity);
    const totalProfit = Math.round(majorProfit * quantity);
     const majorTotal = Math.round((majorEach - (scrollPrice * 3)) * quantity);


     // Helper function to apply red color for negatives
     // Helper to apply value and negative styling
     function formatProfit(cell, value) {
     function set(cell, value) {
       cell.textContent = value;
       cell.textContent = value;
       cell.style.color = value < 0 ? '#ee4231 !important' : '';
       cell.style.color = value < 0 ? '#ee4231' : '';
     }
     }


     formatProfit(row.querySelector('.minorProfit'), minorProfit);
     set(row.querySelector('.aurumMinorEach'), minorEach);
     formatProfit(row.querySelector('.majorProfit'), majorProfit);
     set(row.querySelector('.aurumMajorEach'), majorEach);
     formatProfit(row.querySelector('.totalProfit'), totalProfit);
     set(row.querySelector('.aurumMinorTotal'), minorTotal);
    set(row.querySelector('.aurumMajorTotal'), majorTotal);
   });
   });
}
}
Line 36: Line 38:
document.getElementById('quantity').addEventListener('input', calculateProfits);
document.getElementById('quantity').addEventListener('input', calculateProfits);


calculateProfits(); // Initial call
document.addEventListener('DOMContentLoaded', calculateProfits);
</script>
</script>
</html>
</html>

Revision as of 14:18, 26 June 2025

Scroll Price:
Quantity: