MediaWiki:Common.js

From Roat Pkz
Revision as of 02:45, 5 March 2026 by Hefner (talk | contribs)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// == Common.js Minimal Droprate Calculator ==
// Runs only on pages with #calcContainer
document.addEventListener("DOMContentLoaded", function() {
    var container = document.getElementById("calcContainer");
    if (!container) return;

    // Build the calculator HTML
    var html = '';
    html += '<div>';
    html += '<label>Base Drop Rate: <input type="number" id="baseRate" value="1000" style="width:80px;"></label>';
    html += '</div>';
    html += '<div>';
    html += '<label>Donator Bonus: <select id="donatorBonus">';
    html += '<option value="0">None</option>';
    html += '<option value="0.10">Bronze (10%)</option>';
    html += '<option value="0.25">Divine (25%)</option>';
    html += '</select></label>';
    html += '</div>';
    html += '<div>';
    html += '<label>Vote Bonus: <select id="voteBonus">';
    html += '<option value="0">None</option>';
    html += '<option value="0.05">5%</option>';
    html += '<option value="0.10">10%</option>';
    html += '</select></label>';
    html += '</div>';
    html += '<div>';
    html += '<label>Skull Bonus: <select id="skullBonus">';
    html += '<option value="0">None</option>';
    html += '<option value="0.05">5%</option>';
    html += '<option value="0.15">15%</option>';
    html += '</select></label>';
    html += '</div>';
    html += '<div>';
    html += '<button id="calcButton">Calculate Drop Rate</button>';
    html += '</div>';
    html += '<div>Final Drop Rate: <span id="finalRate">0</span></div>';

    container.innerHTML = html;

    // Add calculator functionality
    var btn = document.getElementById("calcButton");
    btn.onclick = 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;

        // Apply bonuses multiplicatively
        var finalRate = base * (1 - donator) * (1 - vote) * (1 - skull);

        document.getElementById("finalRate").textContent = finalRate.toFixed(2);
    };
});