MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 42: | Line 42: | ||
}); | }); | ||
// --- DROPRATE CALCULATOR --- | // --- DROPRATE CALCULATOR --- | ||
document.addEventListener("DOMContentLoaded", function() { | |||
var container = document.getElementById(" | var container = document.getElementById("calcContainer"); | ||
if (!container) return; | if (!container) return; | ||
// Build HTML | // Build the calculator HTML | ||
container.innerHTML = | container.innerHTML = '' | ||
'<div style="margin:10px 0;">' + | + '<div style="margin:10px 0;">' | ||
+ ' <label>Base Drop Rate: <input type="number" id="baseRate" value="1000" style="width:80px;"></label>' | |||
+ '</div>' | |||
+ '<div style="margin:10px 0;">' | |||
+ ' <label>Donator Bonus: ' | |||
+ ' <select id="donatorBonus">' | |||
+ ' <option value="0">None</option>' | |||
+ ' <option value="0.10">Bronze (10%)</option>' | |||
+ ' <option value="0.25">Divine (25%)</option>' | |||
+ ' </select>' | |||
+ ' </label>' | |||
+ '</div>' | |||
+ '<div style="margin:10px 0;">' | |||
+ ' <label>Vote Bonus: ' | |||
+ ' <select id="voteBonus">' | |||
+ ' <option value="0">None</option>' | |||
+ ' <option value="0.05">5%</option>' | |||
+ ' <option value="0.10">10%</option>' | |||
+ ' </select>' | |||
+ ' </label>' | |||
+ '</div>' | |||
+ '<div style="margin:10px 0;">' | |||
+ ' <label>Skull Bonus: ' | |||
+ ' <select id="skullBonus">' | |||
+ ' <option value="0">None</option>' | |||
+ ' <option value="0.05">5%</option>' | |||
+ ' <option value="0.15">15%</option>' | |||
+ ' </select>' | |||
+ ' </label>' | |||
+ '</div>' | |||
+ '<div style="margin:10px 0;">' | |||
+ ' <button id="calcButton">Calculate Drop Rate</button>' | |||
+ '</div>' | |||
+ '<div style="margin:10px 0;">Final Drop Rate: <span id="finalRate">0</span></div>'; | |||
// Calculator logic | |||
var btn = document.getElementById("calcButton"); | |||
btn.addEventListener("click", function() { | |||
// | |||
var btn = document.getElementById(" | |||
btn. | |||
var base = parseFloat(document.getElementById("baseRate").value) || 0; | var base = parseFloat(document.getElementById("baseRate").value) || 0; | ||
var donator = parseFloat(document.getElementById("donatorBonus").value) || 0; | var donator = parseFloat(document.getElementById("donatorBonus").value) || 0; | ||
| Line 90: | Line 91: | ||
var skull = parseFloat(document.getElementById("skullBonus").value) || 0; | var skull = parseFloat(document.getElementById("skullBonus").value) || 0; | ||
// | // Multiplicative reduction formula | ||
var finalRate = base | var finalRate = base * (1 - donator) * (1 - vote) * (1 - skull); | ||
document.getElementById(" | document.getElementById("finalRate").textContent = finalRate.toFixed(2); | ||
}; | }); | ||
}); | }); | ||
Revision as of 02:42, 5 March 2026
// --- COMMON.JS: Minimal Calculator (ES5 safe) ---
mw.hook('wikipage.content').add(function () {
var container = document.getElementById("calcContainer");
if (!container) return;
container.innerHTML =
'<div style="margin:10px 0;">' +
'<label>Num1: <input type="number" id="num1" value="0" style="width:60px;"></label> ' +
'<label>Num2: <input type="number" id="num2" value="0" style="width:60px;"></label> ' +
'<label>Operation: ' +
'<select id="op">' +
'<option value="+">+</option>' +
'<option value="-">-</option>' +
'<option value="*">*</option>' +
'<option value="/">/</option>' +
'</select>' +
'</label> ' +
'<button id="calcButton">Calculate</button>' +
'</div>' +
'<div>Result: <span id="result">0</span></div>';
var btn = document.getElementById("calcButton");
btn.onclick = function () {
var a = parseFloat(document.getElementById("num1").value);
var b = parseFloat(document.getElementById("num2").value);
var op = document.getElementById("op").value;
var result;
if (isNaN(a) || isNaN(b)) {
result = "Enter valid numbers";
} else {
switch(op) {
case "+": result = a + b; break;
case "-": result = a - b; break;
case "*": result = a * b; break;
case "/": result = b !== 0 ? a / b : "∞"; break;
default: result = "Error";
}
}
document.getElementById("result").textContent = result;
};
});
// --- DROPRATE CALCULATOR ---
document.addEventListener("DOMContentLoaded", function() {
var container = document.getElementById("calcContainer");
if (!container) return;
// Build the calculator HTML
container.innerHTML = ''
+ '<div style="margin:10px 0;">'
+ ' <label>Base Drop Rate: <input type="number" id="baseRate" value="1000" style="width:80px;"></label>'
+ '</div>'
+ '<div style="margin:10px 0;">'
+ ' <label>Donator Bonus: '
+ ' <select id="donatorBonus">'
+ ' <option value="0">None</option>'
+ ' <option value="0.10">Bronze (10%)</option>'
+ ' <option value="0.25">Divine (25%)</option>'
+ ' </select>'
+ ' </label>'
+ '</div>'
+ '<div style="margin:10px 0;">'
+ ' <label>Vote Bonus: '
+ ' <select id="voteBonus">'
+ ' <option value="0">None</option>'
+ ' <option value="0.05">5%</option>'
+ ' <option value="0.10">10%</option>'
+ ' </select>'
+ ' </label>'
+ '</div>'
+ '<div style="margin:10px 0;">'
+ ' <label>Skull Bonus: '
+ ' <select id="skullBonus">'
+ ' <option value="0">None</option>'
+ ' <option value="0.05">5%</option>'
+ ' <option value="0.15">15%</option>'
+ ' </select>'
+ ' </label>'
+ '</div>'
+ '<div style="margin:10px 0;">'
+ ' <button id="calcButton">Calculate Drop Rate</button>'
+ '</div>'
+ '<div style="margin:10px 0;">Final Drop Rate: <span id="finalRate">0</span></div>';
// Calculator logic
var btn = document.getElementById("calcButton");
btn.addEventListener("click", function() {
var base = parseFloat(document.getElementById("baseRate").value) || 0;
var donator = parseFloat(document.getElementById("donatorBonus").value) || 0;
var vote = parseFloat(document.getElementById("voteBonus").value) || 0;
var skull = parseFloat(document.getElementById("skullBonus").value) || 0;
// Multiplicative reduction formula
var finalRate = base * (1 - donator) * (1 - vote) * (1 - skull);
document.getElementById("finalRate").textContent = finalRate.toFixed(2);
});
});