MediaWiki:Common.js: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
// --- DROPRATE CALCULATOR (ES5 Table Version, Styled Cells) ---
// --- DROPRATE CALCULATOR WITH TABLE ---
mw.hook('wikipage.content').add(function () {
mw.hook('wikipage.content').add(function () {
     var container = document.getElementById("dropCalcContainer");
     var container = document.getElementById("dropCalcContainer");
     if (!container) return;
     if (!container) return;


     // Build HTML using ES5 string concatenation
     // Build HTML: Table
     var html = '';
     container.innerHTML =
    html += '<table style="border-collapse:collapse;margin:10px 0;width:450px;">';
        '<table id="dropCalcTable" style="border-collapse: collapse; width: 100%; max-width: 500px;">' +
    html += '<tr><td>Base Drop Rate:</td><td><input type="number" id="baseRate" value="1000" style="width:80px;"></td></tr>';
        '<thead></thead><tbody></tbody></table>' +
        '<br><button id="calcDropBtn">Calculate Drop Rate</button>' +
        '<div style="margin-top:10px;">Final Drop Rate: <span id="finalDrop">0</span></div>';


     html += '<tr><td>Donator Rank Bonus:</td><td>';
     var table = document.getElementById("dropCalcTable");
    html += '<select id="donatorBonus">';
     var header = table.createTHead();
     html += '<option value="0">None</option>';
     var headerRow = header.insertRow();
     html += '<option value="15">Donator 15%</option>';
     headerRow.innerHTML = "<th>Bonus</th><th>Percentage</th><th>Drop Rate</th>";
     html += '<option value="25">Super Donator 25%</option>';
    html += '<option value="30">Extreme Donator 30%</option>';
    html += '<option value="35">Legendary Donator 35%</option>';
    html += '<option value="40">Royal Donator 40%</option>';
    html += '<option value="45">Divine Donator 45%</option>';
    html += '</select></td></tr>';


     html += '<tr><td>Monster Slayer Perk:</td><td>';
     // Style header
     html += '<select id="slayerBonus">';
    headerRow.style.background = '#4CAF50'; // header background color
     html += '<option value="0">None</option>';
     headerRow.style.color = '#fff';         // header text color
     html += '<option value="10">10%</option>';
     headerRow.style.fontWeight = 'bold';
     html += '</select></td></tr>';
     headerRow.style.textAlign = 'left';
     headerRow.style.padding = '5px';


     html += '<tr><td>Collector\'s Ring Bonus:</td><td>';
     var tbody = table.tBodies[0];
    html += '<select id="ringBonus">';
    html += '<option value="0">None</option>';
    html += '<option value="3">3%</option>';
    html += '<option value="6">6%</option>';
    html += '</select></td></tr>';


     html += '<tr><td>Skull Bonus:</td><td>';
     // Bonus options
     html += '<select id="skullBonus">';
     var bonuses = [
    html += '<option value="0">None</option>';
        {
    html += '<option value="20">20%</option>';
            name: "Donator Rank",
     html += '</select></td></tr>';
            id: "donatorBonus",
            options: [
                {name: "None", value:0},
                {name: "Donator 15%", value:15},
                {name: "Super Donator 25%", value:25},
                {name: "Extreme Donator 30%", value:30},
                {name: "Legendary Donator 35%", value:35},
                {name: "Royal Donator 40%", value:40},
                {name: "Divine Donator 45%", value:45}
            ]
        },
        {
            name: "Monster Slayer Perk",
            id: "slayerBonus",
            options: [
                {name:"None", value:0},
                {name:"10%", value:10}
            ]
        },
        {
            name: "Collector's Ring",
            id: "ringBonus",
            options: [
                {name:"None", value:0},
                {name:"3%", value:3},
                {name:"6%", value:6}
            ]
        },
        {
            name: "Skull Bonus",
            id: "skullBonus",
            options: [
                {name:"None", value:0},
                {name:"20%", value:20}
            ]
        },
        {
            name: "Voting Bonus",
            id: "voteBonus",
            options: [
                {name:"None", value:0},
                {name:"20%", value:20}
            ]
        }
     ];


     html += '<tr><td>Voting Bonus:</td><td>';
     // Populate table rows
     html += '<select id="voteBonus">';
     bonuses.forEach(function(bonus, index) {
    html += '<option value="0">None</option>';
        var row = tbody.insertRow();
    html += '<option value="20">20%</option>';
        row.style.background = index % 2 === 0 ? '#f9f9f9' : '#fff'; // zebra stripes
    html += '</select></td></tr>';


    html += '<tr><td colspan="2" style="text-align:center;"><button id="calcDropBtn" style="margin-top:10px;">Calculate Drop Rate</button></td></tr>';
        // Bonus name cell
    html += '</table>';
        var cell1 = row.insertCell();
        cell1.textContent = bonus.name;
        cell1.style.padding = '5px';


    html += '<div style="margin-top:10px;font-weight:bold;">Final Drop Rate: <span id="finalDrop">0</span></div>';
        // Dropdown cell
        var cell2 = row.insertCell();
        var select = document.createElement('select');
        select.id = bonus.id;
        bonus.options.forEach(function(opt){
            var option = document.createElement('option');
            option.value = opt.value;
            option.textContent = opt.name;
            select.appendChild(option);
        });
        cell2.appendChild(select);
        cell2.style.padding = '5px';


    // Table to show step-by-step calculation
        // Drop rate preview cell
    html += '<table id="dropSteps" style="border-collapse:collapse;margin-top:10px;width:450px;">';
        var cell3 = row.insertCell();
    html += '<tr style="background:#444;color:#fff;"><th style="padding:4px;border:1px solid #999;">Bonus</th><th style="padding:4px;border:1px solid #999;">Percentage</th><th style="padding:4px;border:1px solid #999;">Drop Rate</th></tr>';
        cell3.id = bonus.id + "Preview";
     html += '</table>';
        cell3.textContent = "-";
        cell3.style.padding = '5px';
     });


     container.innerHTML = html;
     // Add base rate input above table
    var baseDiv = document.createElement('div');
    baseDiv.style.margin = '10px 0';
    baseDiv.innerHTML = 'Base Drop Rate: <input type="number" id="baseRate" value="1000" style="width:80px;">';
    container.insertBefore(baseDiv, table);


     // Calculation
     // Calculation
     var btn = document.getElementById("calcDropBtn");
     document.getElementById("calcDropBtn").onclick = function() {
    btn.onclick = function () {
         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 slayer = parseFloat(document.getElementById("slayerBonus").value) || 0;
        var ring = parseFloat(document.getElementById("ringBonus").value) || 0;
        var skull = parseFloat(document.getElementById("skullBonus").value) || 0;
        var vote = parseFloat(document.getElementById("voteBonus").value) || 0;
         var finalRate = base;
         var finalRate = base;
        var stepsTable = document.getElementById("dropSteps");
        // Remove old rows except header
        while(stepsTable.rows.length > 1){ stepsTable.deleteRow(1); }
        function addStep(name, perc) {
            finalRate *= (1 - perc / 100);
            var row = stepsTable.insertRow();
            row.style.background = '#313e59';
            row.style.border = '1px solid #ccc';
            var cell1 = row.insertCell(0);
            var cell2 = row.insertCell(1);
            var cell3 = row.insertCell(2);
            cell1.style.padding = '4px'; cell1.style.border = '1px solid #ccc';
            cell2.style.padding = '4px'; cell2.style.border = '1px solid #ccc';
            cell3.style.padding = '4px'; cell3.style.border = '1px solid #ccc';
            cell1.innerHTML = name;
            cell2.innerHTML = perc + '%';
            cell3.innerHTML = Math.round(finalRate);
        }


         addStep("Donator Bonus", donator);
         bonuses.forEach(function(bonus) {
        addStep("Monster Slayer", slayer);
            var val = parseFloat(document.getElementById(bonus.id).value) || 0;
        addStep("Collector's Ring", ring);
            finalRate *= (1 - val / 100);
        addStep("Skull Bonus", skull);
            document.getElementById(bonus.id + "Preview").textContent = Math.round(finalRate);
         addStep("Voting Bonus", vote);
         });


         document.getElementById("finalDrop").textContent = Math.round(finalRate);
         document.getElementById("finalDrop").textContent = Math.round(finalRate);
     };
     };
});
});

Revision as of 03:22, 5 March 2026

// --- DROPRATE CALCULATOR WITH TABLE ---
mw.hook('wikipage.content').add(function () {
    var container = document.getElementById("dropCalcContainer");
    if (!container) return;

    // Build HTML: Table
    container.innerHTML =
        '<table id="dropCalcTable" style="border-collapse: collapse; width: 100%; max-width: 500px;">' +
        '<thead></thead><tbody></tbody></table>' +
        '<br><button id="calcDropBtn">Calculate Drop Rate</button>' +
        '<div style="margin-top:10px;">Final Drop Rate: <span id="finalDrop">0</span></div>';

    var table = document.getElementById("dropCalcTable");
    var header = table.createTHead();
    var headerRow = header.insertRow();
    headerRow.innerHTML = "<th>Bonus</th><th>Percentage</th><th>Drop Rate</th>";

    // Style header
    headerRow.style.background = '#4CAF50'; // header background color
    headerRow.style.color = '#fff';          // header text color
    headerRow.style.fontWeight = 'bold';
    headerRow.style.textAlign = 'left';
    headerRow.style.padding = '5px';

    var tbody = table.tBodies[0];

    // Bonus options
    var bonuses = [
        {
            name: "Donator Rank",
            id: "donatorBonus",
            options: [
                {name: "None", value:0},
                {name: "Donator 15%", value:15},
                {name: "Super Donator 25%", value:25},
                {name: "Extreme Donator 30%", value:30},
                {name: "Legendary Donator 35%", value:35},
                {name: "Royal Donator 40%", value:40},
                {name: "Divine Donator 45%", value:45}
            ]
        },
        {
            name: "Monster Slayer Perk",
            id: "slayerBonus",
            options: [
                {name:"None", value:0},
                {name:"10%", value:10}
            ]
        },
        {
            name: "Collector's Ring",
            id: "ringBonus",
            options: [
                {name:"None", value:0},
                {name:"3%", value:3},
                {name:"6%", value:6}
            ]
        },
        {
            name: "Skull Bonus",
            id: "skullBonus",
            options: [
                {name:"None", value:0},
                {name:"20%", value:20}
            ]
        },
        {
            name: "Voting Bonus",
            id: "voteBonus",
            options: [
                {name:"None", value:0},
                {name:"20%", value:20}
            ]
        }
    ];

    // Populate table rows
    bonuses.forEach(function(bonus, index) {
        var row = tbody.insertRow();
        row.style.background = index % 2 === 0 ? '#f9f9f9' : '#fff'; // zebra stripes

        // Bonus name cell
        var cell1 = row.insertCell();
        cell1.textContent = bonus.name;
        cell1.style.padding = '5px';

        // Dropdown cell
        var cell2 = row.insertCell();
        var select = document.createElement('select');
        select.id = bonus.id;
        bonus.options.forEach(function(opt){
            var option = document.createElement('option');
            option.value = opt.value;
            option.textContent = opt.name;
            select.appendChild(option);
        });
        cell2.appendChild(select);
        cell2.style.padding = '5px';

        // Drop rate preview cell
        var cell3 = row.insertCell();
        cell3.id = bonus.id + "Preview";
        cell3.textContent = "-";
        cell3.style.padding = '5px';
    });

    // Add base rate input above table
    var baseDiv = document.createElement('div');
    baseDiv.style.margin = '10px 0';
    baseDiv.innerHTML = 'Base Drop Rate: <input type="number" id="baseRate" value="1000" style="width:80px;">';
    container.insertBefore(baseDiv, table);

    // Calculation
    document.getElementById("calcDropBtn").onclick = function() {
        var base = parseFloat(document.getElementById("baseRate").value) || 0;
        var finalRate = base;

        bonuses.forEach(function(bonus) {
            var val = parseFloat(document.getElementById(bonus.id).value) || 0;
            finalRate *= (1 - val / 100);
            document.getElementById(bonus.id + "Preview").textContent = Math.round(finalRate);
        });

        document.getElementById("finalDrop").textContent = Math.round(finalRate);
    };
});