MediaWiki:Common.js: Difference between revisions
From EQOA Sandstorm Wiki
Jump to navigationJump to search
RenodorDev (talk | contribs) No edit summary |
RenodorDev (talk | contribs) No edit summary |
||
| Line 55: | Line 55: | ||
} | } | ||
})(); | })(); | ||
mw.hook('wikipage.content').add(function () { | |||
const table = document.getElementById('items-found-here-table'); | |||
if (!table) return; | |||
const filters = { | |||
item: document.getElementById('filter-item'), | |||
mob: document.getElementById('filter-mob'), | |||
className: document.getElementById('filter-class'), | |||
lvlMin: document.getElementById('filter-lvl-min'), | |||
hpMin: document.getElementById('filter-hp-min'), | |||
powMin: document.getElementById('filter-pow-min'), | |||
acMin: document.getElementById('filter-ac-min'), | |||
dmgMin: document.getElementById('filter-dmg-min') | |||
}; | |||
const clearButton = document.getElementById('clear-item-filters'); | |||
function getCellNumber(row, index) { | |||
const text = row.cells[index]?.textContent.trim() || ''; | |||
const num = parseFloat(text.replace(/[^\d.-]/g, '')); | |||
return isNaN(num) ? 0 : num; | |||
} | |||
function getCellText(row, index) { | |||
return (row.cells[index]?.textContent || '').toLowerCase(); | |||
} | |||
function filterTable() { | |||
const itemText = filters.item.value.toLowerCase(); | |||
const mobText = filters.mob.value.toLowerCase(); | |||
const classText = filters.className.value.toLowerCase(); | |||
const lvlMin = parseFloat(filters.lvlMin.value) || null; | |||
const hpMin = parseFloat(filters.hpMin.value) || null; | |||
const powMin = parseFloat(filters.powMin.value) || null; | |||
const acMin = parseFloat(filters.acMin.value) || null; | |||
const dmgMin = parseFloat(filters.dmgMin.value) || null; | |||
for (let i = 1; i < table.rows.length; i++) { | |||
const row = table.rows[i]; | |||
const item = getCellText(row, 0); | |||
const mob = getCellText(row, 1); | |||
const className = getCellText(row, 2); | |||
const lvl = getCellNumber(row, 3); | |||
const dmg = getCellNumber(row, 4); | |||
const ac = getCellNumber(row, 5); | |||
const hp = getCellNumber(row, 13); | |||
const pow = getCellNumber(row, 15); | |||
let show = true; | |||
if (itemText && !item.includes(itemText)) show = false; | |||
if (mobText && !mob.includes(mobText)) show = false; | |||
if (classText && !className.includes(classText)) show = false; | |||
if (lvlMin !== null && lvl < lvlMin) show = false; | |||
if (dmgMin !== null && dmg < dmgMin) show = false; | |||
if (acMin !== null && ac < acMin) show = false; | |||
if (hpMin !== null && hp < hpMin) show = false; | |||
if (powMin !== null && pow < powMin) show = false; | |||
row.style.display = show ? '' : 'none'; | |||
} | |||
} | |||
Object.values(filters).forEach(function (input) { | |||
if (input) input.addEventListener('input', filterTable); | |||
}); | |||
if (clearButton) { | |||
clearButton.addEventListener('click', function () { | |||
Object.values(filters).forEach(function (input) { | |||
if (input) input.value = ''; | |||
}); | |||
filterTable(); | |||
}); | |||
} | |||
}); | |||
Revision as of 01:06, 14 May 2026
/* Any JavaScript here will be loaded for all users on every page load. */
( function () {
// only run when DOM ready
function initRaidChecks() {
// find containers
var containers = document.querySelectorAll('.raid-checkboxify');
if (!containers.length) return;
containers.forEach(function (container, idx) {
var links = Array.from(container.querySelectorAll('a'));
links.forEach(function (a, i) {
// skip if it's already processed
if (a.classList.contains('raid-processed')) return;
// create checkbox input
var cb = document.createElement('input');
cb.type = 'checkbox';
cb.className = 'raid-checkbox-input';
cb.style.marginRight = '8px';
cb.style.verticalAlign = 'middle';
// wrap the link & checkbox in a label so clicking text toggles checkbox
var label = document.createElement('label');
label.style.display = 'block';
label.style.cursor = 'pointer';
// move link inside label
a.parentNode.insertBefore(label, a);
label.appendChild(cb);
label.appendChild(a);
a.classList.add('raid-processed');
// restore state from localStorage
var key = 'raidcheck:' + (document.title || location.pathname) + ':' + a.getAttribute('href');
try {
var stored = localStorage.getItem(key);
if (stored === '1') cb.checked = true;
} catch (e) {}
cb.addEventListener('change', function () {
try {
if (cb.checked) localStorage.setItem(key, '1');
else localStorage.removeItem(key);
} catch (e) {}
});
});
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initRaidChecks);
} else {
initRaidChecks();
}
})();
mw.hook('wikipage.content').add(function () {
const table = document.getElementById('items-found-here-table');
if (!table) return;
const filters = {
item: document.getElementById('filter-item'),
mob: document.getElementById('filter-mob'),
className: document.getElementById('filter-class'),
lvlMin: document.getElementById('filter-lvl-min'),
hpMin: document.getElementById('filter-hp-min'),
powMin: document.getElementById('filter-pow-min'),
acMin: document.getElementById('filter-ac-min'),
dmgMin: document.getElementById('filter-dmg-min')
};
const clearButton = document.getElementById('clear-item-filters');
function getCellNumber(row, index) {
const text = row.cells[index]?.textContent.trim() || '';
const num = parseFloat(text.replace(/[^\d.-]/g, ''));
return isNaN(num) ? 0 : num;
}
function getCellText(row, index) {
return (row.cells[index]?.textContent || '').toLowerCase();
}
function filterTable() {
const itemText = filters.item.value.toLowerCase();
const mobText = filters.mob.value.toLowerCase();
const classText = filters.className.value.toLowerCase();
const lvlMin = parseFloat(filters.lvlMin.value) || null;
const hpMin = parseFloat(filters.hpMin.value) || null;
const powMin = parseFloat(filters.powMin.value) || null;
const acMin = parseFloat(filters.acMin.value) || null;
const dmgMin = parseFloat(filters.dmgMin.value) || null;
for (let i = 1; i < table.rows.length; i++) {
const row = table.rows[i];
const item = getCellText(row, 0);
const mob = getCellText(row, 1);
const className = getCellText(row, 2);
const lvl = getCellNumber(row, 3);
const dmg = getCellNumber(row, 4);
const ac = getCellNumber(row, 5);
const hp = getCellNumber(row, 13);
const pow = getCellNumber(row, 15);
let show = true;
if (itemText && !item.includes(itemText)) show = false;
if (mobText && !mob.includes(mobText)) show = false;
if (classText && !className.includes(classText)) show = false;
if (lvlMin !== null && lvl < lvlMin) show = false;
if (dmgMin !== null && dmg < dmgMin) show = false;
if (acMin !== null && ac < acMin) show = false;
if (hpMin !== null && hp < hpMin) show = false;
if (powMin !== null && pow < powMin) show = false;
row.style.display = show ? '' : 'none';
}
}
Object.values(filters).forEach(function (input) {
if (input) input.addEventListener('input', filterTable);
});
if (clearButton) {
clearButton.addEventListener('click', function () {
Object.values(filters).forEach(function (input) {
if (input) input.value = '';
});
filterTable();
});
}
});