Difference between revisions of "MediaWiki:Calculator.js/Mana Regeneration.js"
m |
m |
||
Line 4: | Line 4: | ||
var ManaPerSecondCalculator = Calculator.extend({ | var ManaPerSecondCalculator = Calculator.extend({ | ||
init: function() { | init: function() { | ||
+ | var calculate = function(input, label) { | ||
+ | if (input.value) { | ||
+ | if (isNumeric(input.value)) { | ||
+ | var percentChance = Math.pow(input.value, (5 / 9)); | ||
+ | if (percentChance > 100) { | ||
+ | percentChance = 100; | ||
+ | } | ||
+ | percentChance = percentChance.toFixed(3); | ||
+ | removeChildren(label); | ||
+ | label.appendChild(document.createTextNode(percentChance + '% Chance')); | ||
+ | } | ||
+ | } | ||
+ | }; | ||
var calcTableRow = document.createElement('tr'); | var calcTableRow = document.createElement('tr'); | ||
var calcTableCell = document.createElement('td'); | var calcTableCell = document.createElement('td'); | ||
− | var | + | var luckInput = document.createElement('input'); |
− | + | ||
− | + | ||
− | + | ||
var calculateButton = document.createElement('input'); | var calculateButton = document.createElement('input'); | ||
− | var | + | var percentChanceLabel = document.createElement('div'); |
calcTableCell.style.textAlign = 'right'; | calcTableCell.style.textAlign = 'right'; | ||
− | calcTableCell.appendChild(document.createTextNode(' | + | calcTableCell.appendChild(document.createTextNode('Luck:')); |
calcTableRow.appendChild(calcTableCell); | calcTableRow.appendChild(calcTableCell); | ||
− | + | luckInput.id = 'luckInput'; | |
− | + | luckInput.maxLength = '4'; | |
− | + | luckInput.type = 'text'; | |
+ | luckInput.style.width = '35px'; | ||
+ | luckInput.onkeyup = function(keyEvent) { | ||
+ | var keyID = window.event ? event.keyCode : keyEvent.keyCode; | ||
+ | if (keyID == 13) | ||
+ | calculate(luckInput, percentChanceLabel); | ||
+ | }; | ||
calcTableCell = document.createElement('td'); | calcTableCell = document.createElement('td'); | ||
− | calcTableCell.appendChild( | + | calcTableCell.appendChild(luckInput); |
calcTableRow.appendChild(calcTableCell); | calcTableRow.appendChild(calcTableCell); | ||
calculateButton.type = 'button'; | calculateButton.type = 'button'; | ||
calculateButton.value = 'Calculate >>'; | calculateButton.value = 'Calculate >>'; | ||
+ | calculateButton.onclick = function() { | ||
+ | calculate(luckInput, percentChanceLabel); | ||
+ | }; | ||
calcTableCell = document.createElement('td'); | calcTableCell = document.createElement('td'); | ||
calcTableCell.appendChild(calculateButton); | calcTableCell.appendChild(calculateButton); | ||
calcTableRow.appendChild(calcTableCell); | calcTableRow.appendChild(calcTableCell); | ||
− | + | percentChanceLabel.appendChild(document.createTextNode('0.000% Chance')); | |
− | + | percentChanceLabel.style.textAlign = 'right'; | |
− | + | percentChanceLabel.style.width = '110px'; | |
calcTableCell = document.createElement('td'); | calcTableCell = document.createElement('td'); | ||
calcTableCell.appendChild(percentChanceLabel); | calcTableCell.appendChild(percentChanceLabel); |
Revision as of 12:00, 4 May 2010
/** * Calculator that calculates your mana regenerated per second based on Meditation, Focus, Intelligence, and equipped MR. */ var ManaPerSecondCalculator = Calculator.extend({ init: function() { var calculate = function(input, label) { if (input.value) { if (isNumeric(input.value)) { var percentChance = Math.pow(input.value, (5 / 9)); if (percentChance > 100) { percentChance = 100; } percentChance = percentChance.toFixed(3); removeChildren(label); label.appendChild(document.createTextNode(percentChance + '% Chance')); } } }; var calcTableRow = document.createElement('tr'); var calcTableCell = document.createElement('td'); var luckInput = document.createElement('input'); var calculateButton = document.createElement('input'); var percentChanceLabel = document.createElement('div'); calcTableCell.style.textAlign = 'right'; calcTableCell.appendChild(document.createTextNode('Luck:')); calcTableRow.appendChild(calcTableCell); luckInput.id = 'luckInput'; luckInput.maxLength = '4'; luckInput.type = 'text'; luckInput.style.width = '35px'; luckInput.onkeyup = function(keyEvent) { var keyID = window.event ? event.keyCode : keyEvent.keyCode; if (keyID == 13) calculate(luckInput, percentChanceLabel); }; calcTableCell = document.createElement('td'); calcTableCell.appendChild(luckInput); calcTableRow.appendChild(calcTableCell); calculateButton.type = 'button'; calculateButton.value = 'Calculate >>'; calculateButton.onclick = function() { calculate(luckInput, percentChanceLabel); }; calcTableCell = document.createElement('td'); calcTableCell.appendChild(calculateButton); calcTableRow.appendChild(calcTableCell); percentChanceLabel.appendChild(document.createTextNode('0.000% Chance')); percentChanceLabel.style.textAlign = 'right'; percentChanceLabel.style.width = '110px'; calcTableCell = document.createElement('td'); calcTableCell.appendChild(percentChanceLabel); calcTableRow.appendChild(calcTableCell); this._super(calcTableRow, 'ManaPerSecond', 'Mana Per Second', 4); } }); function searchForCalculators() { var calculators = document.getElementsByTagName('div'); for (var i in calculators) { if (calculators[i].id == 'ManaPerSecond') { new ManaPerSecondCalculator(); } } } addOnloadHook(searchForCalculators);