Widget:Calculator/Magic/Aurum: Difference between revisions
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; | ||
// | // Each values | ||
const | const minorEach = Math.round(itemPrice * 0.0375); | ||
const | const majorEach = Math.round(itemPrice * 0.5); | ||
const | // Profit after scroll cost × quantity | ||
const | const minorTotal = Math.round((minorEach - scrollPrice) * quantity); | ||
const majorTotal = Math.round((majorEach - (scrollPrice * 3)) * quantity); | |||
// Helper | // Helper to apply value and negative styling | ||
function | function set(cell, value) { | ||
cell.textContent = value; | cell.textContent = value; | ||
cell.style.color = value < 0 ? '#ee4231 | cell.style.color = value < 0 ? '#ee4231' : ''; | ||
} | } | ||
set(row.querySelector('.aurumMinorEach'), minorEach); | |||
set(row.querySelector('.aurumMajorEach'), majorEach); | |||
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 | document.addEventListener('DOMContentLoaded', calculateProfits); | ||
</script> | </script> | ||
</html> | </html> |
Revision as of 14:18, 26 June 2025