MediaWiki:DropCalc.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
| Line 1: | Line 1: | ||
// --- DROPRATE CALCULATOR WITH TABLE --- | // --- DROPRATE CALCULATOR WITH TABLE & ICONS --- | ||
mw.hook('wikipage.content').add(function () { | mw.hook('wikipage.content').add(function () { | ||
var container = document.getElementById("dropCalcContainer"); | var container = document.getElementById("dropCalcContainer"); | ||
| Line 14: | Line 14: | ||
var header = table.createTHead(); | var header = table.createTHead(); | ||
var headerRow = header.insertRow(); | var headerRow = header.insertRow(); | ||
headerRow.innerHTML = | headerRow.innerHTML = | ||
'<th style="padding-left: 10px;">Bonus</th>' + | '<th style="padding-left: 10px;">Bonus</th>' + | ||
'<th>Percentage</th>' + | '<th>Percentage</th>' + | ||
'<th>Drop Rate</th>'; | '<th>Drop Rate</th>'; | ||
headerRow.style.background = '#222e45'; | headerRow.style.background = '#222e45'; | ||
headerRow.style.color = '#fff'; | headerRow.style.color = '#fff'; | ||
| Line 25: | Line 27: | ||
var tbody = table.tBodies[0]; | var tbody = table.tBodies[0]; | ||
// Bonuses with custom icons for Donator Rank | |||
var bonuses = [ | var bonuses = [ | ||
{ name: "Donator Rank", id: "donatorBonus", options: [ | { | ||
name: "Donator Rank", | |||
id: "donatorBonus", | |||
options: [ | |||
{name: "None", value:0, icon:"none.png"}, | |||
{name: "Donator 15%", value:15, icon:"Donator.png"}, | |||
{name: "Super Donator 25%", value:25, icon:"superdonator25.png"}, | |||
{name: "Extreme Donator 30%", value:30, icon:"extremedonator30.png"}, | |||
{name: "Legendary Donator 35%", value:35, icon:"legendarydonator35.png"}, | |||
{name: "Royal Donator 40%", value:40, icon:"royaldonator40.png"}, | |||
{name: "Divine Donator 45%", value:45, icon:"divinedonator45.png"} | |||
] | |||
}, | |||
{ name: "Monster Slayer Perk", id: "slayerBonus", options: [{name:"None",value:0},{name:"10%",value:10}]}, | { 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: "Collector's Ring", id: "ringBonus", options: [{name:"None",value:0},{name:"3%",value:3},{name:"6%",value:6}]}, | ||
| Line 36: | Line 48: | ||
]; | ]; | ||
// | // Populate table rows | ||
bonuses.forEach(function(bonus, index) { | bonuses.forEach(function(bonus, index) { | ||
var row = tbody.insertRow(); | var row = tbody.insertRow(); | ||
| Line 48: | Line 58: | ||
var cell2 = row.insertCell(); | 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; | |||
// Add icon for Donator Rank | |||
if (bonus.id === 'donatorBonus' && opt.icon) { | |||
option.style.backgroundImage = `url('images/${opt.icon}')`; | |||
option.style.backgroundRepeat = 'no-repeat'; | |||
option.style.backgroundSize = '16px 16px'; | |||
option.style.paddingLeft = '20px'; | |||
} | |||
select.appendChild(option); | |||
}); | |||
cell2.appendChild(select); | |||
cell2.style.padding = '5px'; | cell2.style.padding = '5px'; | ||
| Line 55: | Line 83: | ||
cell3.style.padding = '5px'; | cell3.style.padding = '5px'; | ||
// Recalculate when bonus changes | |||
select.addEventListener('change', function() { | |||
document.getElementById("calcDropBtn").click(); | |||
}); | |||
}); | }); | ||
| Line 123: | Line 92: | ||
var baseDiv = document.createElement('div'); | var baseDiv = document.createElement('div'); | ||
baseDiv.style.margin = '10px 0'; | baseDiv.style.margin = '10px 0'; | ||
baseDiv.innerHTML = | baseDiv.innerHTML = | ||
'Item: <input list="dropItems" id="itemSearch" placeholder="Search item..." style="width: | 'Item: <input list="dropItems" id="itemSearch" placeholder="Search item..." style="width:250px;"> ' + | ||
'Base Rate: <input type="number" id="baseRate" value="1000" style="width:80px;">' + | 'Base Rate: <input type="number" id="baseRate" value="1000" style="width:80px;">' + | ||
'<datalist id="dropItems">' + | '<datalist id="dropItems">' + | ||
| Line 139: | Line 109: | ||
'<option data-rate="2560" value="Enchanted Collector\'s Ring (6%) (1/2560)">' + | '<option data-rate="2560" value="Enchanted Collector\'s Ring (6%) (1/2560)">' + | ||
'</datalist>'; | '</datalist>'; | ||
container.insertBefore(baseDiv, table); | container.insertBefore(baseDiv, table); | ||
// | // Auto-fill base rate, recalc, and disable Skull for TokHaar-kal | ||
var itemInput = document.getElementById("itemSearch"); | var itemInput = document.getElementById("itemSearch"); | ||
var skullDisabledItems = ["TokHaar-kal"]; | |||
itemInput.addEventListener('input', function() { | itemInput.addEventListener('input', function() { | ||
var options = document.getElementById("dropItems").options; | var options = document.getElementById("dropItems").options; | ||
| Line 153: | Line 124: | ||
document.getElementById("baseRate").value = rate; | document.getElementById("baseRate").value = rate; | ||
var skullSelect = document.getElementById("skullBonus"); | var skullSelect = document.getElementById("skullBonus"); | ||
var rawName = val.replace(/\s*\(1\/\d+\)$/, ''); | var rawName = val.replace(/\s*\(1\/\d+\)$/, ''); | ||
if(skullDisabledItems.includes(rawName)) { | if (skullDisabledItems.includes(rawName)) { | ||
skullSelect.disabled = true; | skullSelect.disabled = true; | ||
skullSelect.style.opacity = 0.5; | skullSelect.style.opacity = 0.5; | ||
| Line 168: | Line 138: | ||
} | } | ||
} | } | ||
}); | |||
// Recalculate when any bonus changes | |||
bonuses.forEach(function(bonus) { | |||
document.getElementById(bonus.id).addEventListener('change', function() { | |||
document.getElementById("calcDropBtn").click(); | |||
}); | |||
}); | }); | ||
| Line 175: | Line 152: | ||
var finalRate = base; | var finalRate = base; | ||
bonuses.forEach(function(bonus){ | bonuses.forEach(function(bonus) { | ||
var | var val = parseFloat(document.getElementById(bonus.id).value) || 0; | ||
finalRate *= (1 - val / 100); | finalRate *= (1 - val / 100); | ||
document.getElementById(bonus.id + "Preview").textContent = Math.floor(finalRate); | document.getElementById(bonus.id + "Preview").textContent = Math.floor(finalRate); | ||
Revision as of 15:56, 5 March 2026
// --- DROPRATE CALCULATOR WITH TABLE & ICONS ---
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];
// Bonuses with custom icons for Donator Rank
var bonuses = [
{
name: "Donator Rank",
id: "donatorBonus",
options: [
{name: "None", value:0, icon:"none.png"},
{name: "Donator 15%", value:15, icon:"Donator.png"},
{name: "Super Donator 25%", value:25, icon:"superdonator25.png"},
{name: "Extreme Donator 30%", value:30, icon:"extremedonator30.png"},
{name: "Legendary Donator 35%", value:35, icon:"legendarydonator35.png"},
{name: "Royal Donator 40%", value:40, icon:"royaldonator40.png"},
{name: "Divine Donator 45%", value:45, icon:"divinedonator45.png"}
]
},
{ 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';
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;
// Add icon for Donator Rank
if (bonus.id === 'donatorBonus' && opt.icon) {
option.style.backgroundImage = `url('images/${opt.icon}')`;
option.style.backgroundRepeat = 'no-repeat';
option.style.backgroundSize = '16px 16px';
option.style.paddingLeft = '20px';
}
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';
// Recalculate when bonus changes
select.addEventListener('change', function() {
document.getElementById("calcDropBtn").click();
});
});
// 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:250px;"> ' +
'Base Rate: <input type="number" id="baseRate" value="1000" style="width:80px;">' +
'<datalist id="dropItems">' +
'<option data-rate="256" value="Zaryte Crossbow (1/256)">' +
'<option data-rate="350" value="Torva Full Helm (1/350)">' +
'<option data-rate="2560" value="Voidwaker gem (1/2560)">' +
'<option data-rate="2560" value="Voidwaker hilt (1/2560)">' +
'<option data-rate="2560" value="Voidwaker blade (1/2560)">' +
'<option data-rate="128" value="Ancient godsword (1/128)">' +
'<option data-rate="64" value="Zaryte vambraces (1/64)">' +
'<option data-rate="10240" value="Elysian sigil (1/10240)">' +
'<option data-rate="1024" value="Smoudering heart (1/1024)">' +
'<option data-rate="75" value="TokHaar-kal (1/75)">' +
'<option data-rate="2560" value="Enchanted Collector\'s Ring (6%) (1/2560)">' +
'</datalist>';
container.insertBefore(baseDiv, table);
// Auto-fill base rate, recalc, and disable Skull for TokHaar-kal
var itemInput = document.getElementById("itemSearch");
var skullDisabledItems = ["TokHaar-kal"];
itemInput.addEventListener('input', 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;
var skullSelect = document.getElementById("skullBonus");
var rawName = val.replace(/\s*\(1\/\d+\)$/, '');
if (skullDisabledItems.includes(rawName)) {
skullSelect.disabled = true;
skullSelect.style.opacity = 0.5;
} else {
skullSelect.disabled = false;
skullSelect.style.opacity = 1;
}
document.getElementById("calcDropBtn").click();
break;
}
}
});
// Recalculate when any bonus changes
bonuses.forEach(function(bonus) {
document.getElementById(bonus.id).addEventListener('change', function() {
document.getElementById("calcDropBtn").click();
});
});
// 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);
};
});