MediaWiki:SlayerPointsCalc.js: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
No edit summary
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
mw.hook('wikipage.content').add(function () {
mw.hook('wikipage.content').add(function () {


    // Only run on the correct page
     if (mw.config.get('wgPageName') !== "Slayer_points_calculator") return;
     if (mw.config.get('wgPageName') !== "Slayer_points_calculator") return;
     var container = document.getElementById("slayerCalcContainer");
     var container = document.getElementById("slayerCalcContainer");
     if (!container) return;
     if (!container) return;
Line 23: Line 21:


         '<div style="margin-bottom:10px;">' +
         '<div style="margin-bottom:10px;">' +
         '<label><input type="checkbox" id="slayerGatherer"> Slayer Gatherer (+50% points per task)</label>' +
         '<label><input type="checkbox" id="slayerGatherer"> Slayer gatherer clan chat perk (+50% points per task)</label>' +
         '</div>' +
         '</div>' +


         '<div style="margin-bottom:10px;">' +
         '<div style="margin-bottom:10px;">' +
         'Avg task duration: <input type="number" id="taskMinutes" value="5" min="1" style="width:60px;"> minutes' +
         'Average task duration: <input type="number" id="taskMinutes" value="5" min="1" style="width:60px;"> minutes' +
         '</div>' +
         '</div>' +


Line 33: Line 31:
         '<thead>' +
         '<thead>' +
         '<tr style="background:#222e45;color:#fff;">' +
         '<tr style="background:#222e45;color:#fff;">' +
         '<th style="padding:8px;text-align:left; border-right:2px solid #444;">Task</th>' +
         '<th style="padding:8px;text-align:left; border-right:1px solid #596e96;">Task</th>' +
         '<th style="padding:8px;text-align:center;">Points</th>' +
         '<th style="padding:8px;text-align:center;">Points</th>' +
         '</tr>' +
         '</tr>' +
Line 39: Line 37:
         '<tbody></tbody>' +
         '<tbody></tbody>' +
         '</table>';
         '</table>';
    // Table border styling
    var table = document.getElementById("slayerTable");
    table.style.border = "1px solid #596e96"; // your border color
    table.style.borderCollapse = "collapse";
    table.style.borderRadius = "8px";


     var basePoints = 25;
     var basePoints = 25;
Line 53: Line 57:
     var tbody = document.querySelector("#slayerTable tbody");
     var tbody = document.querySelector("#slayerTable tbody");


    // Add table rows for milestones
     milestones.forEach(function(milestone, index){
     milestones.forEach(function(milestone, index){
         var row = tbody.insertRow();
         var row = tbody.insertRow();
Line 66: Line 69:
         cell1.textContent = milestone.name;
         cell1.textContent = milestone.name;
         cell1.style.padding = "8px";
         cell1.style.padding = "8px";
         cell1.style.borderRight = "2px solid #888"; // vertical bar
         cell1.style.borderRight = "1px solid #596e96";


         var cell2 = row.insertCell();
         var cell2 = row.insertCell();
         cell2.id = "points_" + index;
         cell2.id = "points_" + index;
         cell2.style.textAlign = "center";
         cell2.style.textAlign = "center";
         cell2.style.padding = "8px 0 8px 10px"; // padding-left for spacing
         cell2.style.padding = "8px 0 8px 10px";
     });
     });


     // Add bottom row for Average Points per Hour as single cell
     // Bottom row for Average Points per Hour
     var pphRow = tbody.insertRow();
     var pphRow = tbody.insertRow();
     pphRow.style.background = "#222e45";
     pphRow.style.background = "#313e59";
     pphRow.style.color = "#fff";
     pphRow.style.color = "#fff";


     var cell = pphRow.insertCell();
     var cell = pphRow.insertCell();
     cell.colSpan = 2; // spans both columns
     cell.colSpan = 2;
     cell.style.padding = "8px";
     cell.style.padding = "8px";
     cell.style.textAlign = "center";
     cell.style.textAlign = "center";
     cell.style.borderTop = "2px solid #888"; // horizontal line
     cell.style.borderTop = "1px solid #596e96";
     cell.id = "pointsPerHourCell"; // same ID for updating text
     cell.id = "pointsPerHourCell";


    // Calculate average points per task (1,000-task cycle)
     function calculateAveragePointsPerTask() {
     function calculateAveragePointsPerTask() {
         var taskCounts = {
         var taskCounts = {
Line 113: Line 115:
         var averagePoints = calculateAveragePointsPerTask() * multiplierBoost * (1 + gatherer);
         var averagePoints = calculateAveragePointsPerTask() * multiplierBoost * (1 + gatherer);


        // Update table points
         milestones.forEach(function(milestone, index){
         milestones.forEach(function(milestone, index){
             var points = basePoints * milestone.multiplier * multiplierBoost * (1 + gatherer);
             var points = basePoints * milestone.multiplier * multiplierBoost * (1 + gatherer);
Line 119: Line 120:
         });
         });


         // Update Average Points per Hour bottom row
         // Bold only the number in bottom cell
         var minutes = parseFloat(document.getElementById("taskMinutes").value) || 1;
         var minutes = parseFloat(document.getElementById("taskMinutes").value) || 1;
         var pph = averagePoints * (60 / minutes);
         var pph = averagePoints * (60 / minutes);
         document.getElementById("pointsPerHourCell").textContent = "Average Points per Hour: " + Math.floor(pph);
         document.getElementById("pointsPerHourCell").innerHTML =  
            'Average Points per Hour: <strong>' + Math.floor(pph) + '</strong>';
     }
     }


Line 130: Line 132:
     document.getElementById("taskMinutes").addEventListener("input", updatePoints);
     document.getElementById("taskMinutes").addEventListener("input", updatePoints);


    // Initial calculation
     updatePoints();
     updatePoints();
});
});

Latest revision as of 01:55, 7 March 2026

mw.hook('wikipage.content').add(function () {

    if (mw.config.get('wgPageName') !== "Slayer_points_calculator") return;
    var container = document.getElementById("slayerCalcContainer");
    if (!container) return;

    // Build UI
    container.innerHTML =
        '<div style="margin-bottom:10px;">' +
        'Donator Boost: ' +
        '<select id="donatorBoost">' +
        '<option value="0">None</option>' +
        '<option value="5">Donator (+5%)</option>' +
        '<option value="10">Super Donator (+10%)</option>' +
        '<option value="15">Extreme Donator (+15%)</option>' +
        '<option value="25">Legendary Donator (+25%)</option>' +
        '<option value="50">Royal Donator (+50%)</option>' +
        '<option value="75">Divine Donator (+75%)</option>' +
        '</select>' +
        '</div>' +

        '<div style="margin-bottom:10px;">' +
        '<label><input type="checkbox" id="slayerGatherer"> Slayer gatherer clan chat perk (+50% points per task)</label>' +
        '</div>' +

        '<div style="margin-bottom:10px;">' +
        'Average task duration: <input type="number" id="taskMinutes" value="5" min="1" style="width:60px;"> minutes' +
        '</div>' +

        '<table id="slayerTable" style="border-collapse:collapse; width:400px;">' +
        '<thead>' +
        '<tr style="background:#222e45;color:#fff;">' +
        '<th style="padding:8px;text-align:left; border-right:1px solid #596e96;">Task</th>' +
        '<th style="padding:8px;text-align:center;">Points</th>' +
        '</tr>' +
        '</thead>' +
        '<tbody></tbody>' +
        '</table>';

    // Table border styling
    var table = document.getElementById("slayerTable");
    table.style.border = "1px solid #596e96"; // your border color
    table.style.borderCollapse = "collapse";
    table.style.borderRadius = "8px";

    var basePoints = 25;

    var milestones = [
        {name:"Normal task", multiplier:1},
        {name:"10th task", multiplier:5},
        {name:"50th task", multiplier:15},
        {name:"100th task", multiplier:25},
        {name:"250th task", multiplier:35},
        {name:"1,000th task", multiplier:50}
    ];

    var tbody = document.querySelector("#slayerTable tbody");

    milestones.forEach(function(milestone, index){
        var row = tbody.insertRow();
        row.style.background = index % 2 ? "#222e45" : "#313e59";
        row.style.color = "#fff";
        row.style.transition = "background 0.2s";

        row.addEventListener("mouseover", function(){ row.style.background = "#3a4b6d"; });
        row.addEventListener("mouseout", function(){ row.style.background = index % 2 ? "#222e45" : "#313e59"; });

        var cell1 = row.insertCell();
        cell1.textContent = milestone.name;
        cell1.style.padding = "8px";
        cell1.style.borderRight = "1px solid #596e96";

        var cell2 = row.insertCell();
        cell2.id = "points_" + index;
        cell2.style.textAlign = "center";
        cell2.style.padding = "8px 0 8px 10px";
    });

    // Bottom row for Average Points per Hour
    var pphRow = tbody.insertRow();
    pphRow.style.background = "#313e59";
    pphRow.style.color = "#fff";

    var cell = pphRow.insertCell();
    cell.colSpan = 2;
    cell.style.padding = "8px";
    cell.style.textAlign = "center";
    cell.style.borderTop = "1px solid #596e96";
    cell.id = "pointsPerHourCell";

    function calculateAveragePointsPerTask() {
        var taskCounts = {
            "1000":1,
            "250":3,
            "100":8,
            "50":8,
            "10":80,
            "normal": 1000 - (1+3+8+8+80)
        };
        var sum = 0;
        sum += taskCounts.normal * basePoints * 1;
        sum += taskCounts["10"] * basePoints * 5;
        sum += taskCounts["50"] * basePoints * 15;
        sum += taskCounts["100"] * basePoints * 25;
        sum += taskCounts["250"] * basePoints * 35;
        sum += taskCounts["1000"] * basePoints * 50;
        return sum / 1000;
    }

    function updatePoints() {
        var boost = parseFloat(document.getElementById("donatorBoost").value) || 0;
        var multiplierBoost = 1 + boost/100;
        var gatherer = document.getElementById("slayerGatherer").checked ? 0.5 : 0;

        var averagePoints = calculateAveragePointsPerTask() * multiplierBoost * (1 + gatherer);

        milestones.forEach(function(milestone, index){
            var points = basePoints * milestone.multiplier * multiplierBoost * (1 + gatherer);
            document.getElementById("points_" + index).textContent = Math.floor(points);
        });

        // Bold only the number in bottom cell
        var minutes = parseFloat(document.getElementById("taskMinutes").value) || 1;
        var pph = averagePoints * (60 / minutes);
        document.getElementById("pointsPerHourCell").innerHTML = 
            'Average Points per Hour: <strong>' + Math.floor(pph) + '</strong>';
    }

    // Event listeners
    document.getElementById("donatorBoost").addEventListener("change", updatePoints);
    document.getElementById("slayerGatherer").addEventListener("change", updatePoints);
    document.getElementById("taskMinutes").addEventListener("input", updatePoints);

    updatePoints();
});