MediaWiki:Common.js: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
Tag: Reverted
No edit summary
Tags: Manual revert Reverted
Line 1: Line 1:
// --- DROPRATE CALCULATOR USING DROPRATES.JS ---
// --- DROPRATE CALCULATOR WITH TABLE ---
mw.loader.using([], function() { // no modules required
mw.hook('wikipage.content').add(function () {
    mw.hook('wikipage.content').add(function () {
    var container = document.getElementById("dropCalcContainer");
    if (!container) return;


         var container = document.getElementById("dropCalcContainer");
    // Build HTML: Table
         if (!container) return;
    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>';


         // Make sure DROPRATES is loaded
    var table = document.getElementById("dropCalcTable");
         if (typeof DROPRATES === "undefined") {
    var header = table.createTHead();
             console.error("DROPRATES is not loaded!");
    var headerRow = header.insertRow();
             return;
 
    headerRow.innerHTML =
         '<th style="padding-left: 10px;">Bonus</th>' +
        '<th>Percentage</th>' +
         '<th>Drop Rate</th>';
 
    headerRow.style.background = '#222e45';
    headerRow.style.color = '#fff';
    headerRow.style.fontWeight = 'bold';
    headerRow.style.textAlign = 'left';
 
    var tbody = table.tBodies[0];
 
    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}
             ]
         }
         }
    ];


        // Build HTML table
    bonuses.forEach(function(bonus, index) {
        container.innerHTML =
            '<table id="dropCalcTable" style="border-collapse: collapse; width: 100%; max-width: 600px;">' +
            '<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 row = tbody.insertRow();
        var header = table.createTHead();
         row.style.background = index % 2 === 0 ? '#313e59' : '#222e45';
        var headerRow = header.insertRow();
         headerRow.innerHTML =
            '<th style="padding-left: 10px;">Bonus</th>' +
            '<th>Percentage</th>' +
            '<th>Drop Rate</th>';
        headerRow.style.background = '#222e45';
        headerRow.style.color = '#fff';
        headerRow.style.fontWeight = 'bold';
        headerRow.style.textAlign = 'left';


         var tbody = table.tBodies[0];
         var cell1 = row.insertCell();
        cell1.textContent = bonus.name;
        cell1.style.padding = '5px';


         var bonuses = [
         var cell2 = row.insertCell();
            {name: "Donator Rank", id: "donatorBonus", options:[
        var select = document.createElement('select');
                {name:"None", value:0},{name:"Donator 15%", value:15},{name:"Super Donator 25%", value:25},
        select.id = bonus.id;
                {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 bonus rows
         bonus.options.forEach(function(opt){
        bonuses.forEach(function(bonus,index){
            var option = document.createElement('option');
            var row = tbody.insertRow();
            option.value = opt.value;
            row.style.background = index % 2 === 0 ? '#313e59' : '#222e45';
            option.textContent = opt.name;
            var cell1 = row.insertCell(); cell1.textContent = bonus.name; cell1.style.padding='5px';
            select.appendChild(option);
            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';
            var cell3 = row.insertCell(); cell3.id = bonus.id + "Preview"; cell3.textContent="-"; cell3.style.padding='5px';
         });
         });


         // Searchable item selector
         cell2.appendChild(select);
        var baseDiv = document.createElement('div');
        cell2.style.padding = '5px';
        baseDiv.style.margin = '10px 0';
 
        baseDiv.innerHTML = 'Item: <input list="dropItems" id="itemSearch" placeholder="Search item..." style="width:250px;"> ' +
        var cell3 = row.insertCell();
            'Base Rate: <input type="number" id="baseRate" value="1000" style="width:80px;">' +
        cell3.id = bonus.id + "Preview";
            '<datalist id="dropItems"></datalist>';
        cell3.textContent = "-";
        container.insertBefore(baseDiv, table);
        cell3.style.padding = '5px';
    });
 
    // Searchable item selector
    var baseDiv = document.createElement('div');
    baseDiv.style.margin = '10px 0';
 
    baseDiv.innerHTML =
        'Item: <input list="dropItems" id="itemSearch" placeholder="Search item..." style="width:220px;"> ' +
        'Base Rate: <input type="number" id="baseRate" value="1000" style="width:80px;">' +
 
        '<datalist id="dropItems">' +
        '<option data-rate="1000" value="Abyssal Whip (1/1000)">' +
        '<option data-rate="512" value="Dragon Boots (1/512)">' +
        '<option data-rate="256" value="Barrows Item (1/256)">' +
        '<option data-rate="128" value="Godsword Shard (1/128)">' +
        '<option data-rate="64" value="Rune Item (1/64)">' +
        '</datalist>';
 
    container.insertBefore(baseDiv, table);
 
    // Auto-fill base rate
    var itemInput = document.getElementById("itemSearch");
 
    itemInput.onchange = function() {
 
        var options = document.getElementById("dropItems").options;
        var val = itemInput.value;
 
        for (var i = 0; i < options.length; i++) {
 
            if (options[i].value === val) {
 
                var rate = options[i].getAttribute("data-rate");
                document.getElementById("baseRate").value = rate;
 
                break;
            }
        }
    };
 
    // 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;


        // Populate datalist from DROPRATES
            finalRate *= (1 - val / 100);
        var dataList = document.getElementById("dropItems");
 
        DROPRATES.forEach(function(item){
             document.getElementById(bonus.id + "Preview").textContent = Math.floor(finalRate);
             var option = document.createElement('option');
            option.value = item[0] + ' (1/' + item[1] + ')';
            option.dataset.rate = item[1];
            dataList.appendChild(option);
         });
         });


         // Auto-fill base rate on selection
         document.getElementById("finalDrop").textContent = Math.floor(finalRate);
        var itemInput = document.getElementById("itemSearch");
    };
        itemInput.onchange = function() {
            var val = itemInput.value;
            var options = dataList.options;
            for (var i = 0; i < options.length; i++) {
                if (options[i].value === val) {
                    document.getElementById("baseRate").value = options[i].dataset.rate;
                    break;
                }
            }
        };


        // Calculate final drop rate
        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.floor(finalRate);
            });
            document.getElementById("finalDrop").textContent = Math.floor(finalRate);
        };
    });
});
});

Revision as of 14:51, 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 style="padding-left: 10px;">Bonus</th>' +
        '<th>Percentage</th>' +
        '<th>Drop Rate</th>';

    headerRow.style.background = '#222e45';
    headerRow.style.color = '#fff';
    headerRow.style.fontWeight = 'bold';
    headerRow.style.textAlign = 'left';

    var tbody = table.tBodies[0];

    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}
            ]
        }
    ];

    bonuses.forEach(function(bonus, index) {

        var row = tbody.insertRow();
        row.style.background = index % 2 === 0 ? '#313e59' : '#222e45';

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

        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';

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

    // Searchable item selector
    var baseDiv = document.createElement('div');
    baseDiv.style.margin = '10px 0';

    baseDiv.innerHTML =
        'Item: <input list="dropItems" id="itemSearch" placeholder="Search item..." style="width:220px;"> ' +
        'Base Rate: <input type="number" id="baseRate" value="1000" style="width:80px;">' +

        '<datalist id="dropItems">' +
        '<option data-rate="1000" value="Abyssal Whip (1/1000)">' +
        '<option data-rate="512" value="Dragon Boots (1/512)">' +
        '<option data-rate="256" value="Barrows Item (1/256)">' +
        '<option data-rate="128" value="Godsword Shard (1/128)">' +
        '<option data-rate="64" value="Rune Item (1/64)">' +
        '</datalist>';

    container.insertBefore(baseDiv, table);

    // Auto-fill base rate
    var itemInput = document.getElementById("itemSearch");

    itemInput.onchange = function() {

        var options = document.getElementById("dropItems").options;
        var val = itemInput.value;

        for (var i = 0; i < options.length; i++) {

            if (options[i].value === val) {

                var rate = options[i].getAttribute("data-rate");
                document.getElementById("baseRate").value = rate;

                break;
            }
        }
    };

    // 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.floor(finalRate);
        });

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

});