MediaWiki:Common.js
From EQOA Sandstorm Wiki
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* 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();
}
})();