MediaWiki:Common.js: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
(add vote boost for drop rate calcs)
 
(25 intermediate revisions by one other user not shown)
Line 1: Line 1:
// --- DROPRATE CALCULATOR WITH TABLE ---
mw.loader.load('/index.php?title=MediaWiki:DropCalc.js&action=raw&ctype=text/javascript');
mw.hook('wikipage.content').add(function () {
mw.loader.load('/index.php?title=MediaWiki:SlayerPointsCalc.js&action=raw&ctype=text/javascript');
    var container = document.getElementById("dropCalcContainer");
mw.loader.load('/index.php?title=MediaWiki:BingoSheet.js&action=raw&ctype=text/javascript');
    if (!container) return;
mw.loader.load('/index.php?title=MediaWiki:TeamBingo.js&action=raw&ctype=text/javascript');
 
mw.loader.load('/index.php?title=MediaWiki:Tierlist.js&action=raw&ctype=text/javascript');
    // Build HTML: Table
mw.loader.load('/index.php?title=MediaWiki:SmoothiesDebtCalculator.js&action=raw&ctype=text/javascript');
    container.innerHTML =
mw.loader.load('/index.php?title=MediaWiki:VoteBoostToggle.js&action=raw&ctype=text/javascript');
        '<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>' +  // move right
    '<th>Percentage</th>' +
    '<th>Drop Rate</th>';
 
    // Style header
    headerRow.style.background = '#222e45'; // 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 ? '#313e59' : '#222e45'; // 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);
    };
});

Latest revision as of 21:24, 18 July 2026

mw.loader.load('/index.php?title=MediaWiki:DropCalc.js&action=raw&ctype=text/javascript');
mw.loader.load('/index.php?title=MediaWiki:SlayerPointsCalc.js&action=raw&ctype=text/javascript');
mw.loader.load('/index.php?title=MediaWiki:BingoSheet.js&action=raw&ctype=text/javascript');
mw.loader.load('/index.php?title=MediaWiki:TeamBingo.js&action=raw&ctype=text/javascript');
mw.loader.load('/index.php?title=MediaWiki:Tierlist.js&action=raw&ctype=text/javascript');
mw.loader.load('/index.php?title=MediaWiki:SmoothiesDebtCalculator.js&action=raw&ctype=text/javascript');
mw.loader.load('/index.php?title=MediaWiki:VoteBoostToggle.js&action=raw&ctype=text/javascript');