MediaWiki:Common.js
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)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
(function () {
function applyWidthMode() {
var mode = localStorage.getItem('rpgc-width-mode') || 'readable';
document.body.classList.remove('rpgc-readable-width', 'rpgc-full-width');
if (mode === 'full') {
document.body.classList.add('rpgc-full-width');
} else {
document.body.classList.add('rpgc-readable-width');
}
var button = document.getElementById('rpgc-width-toggle');
if (button) {
button.textContent = mode === 'full' ? 'Readable width' : 'Full width';
}
}
function addToggle() {
if (document.getElementById('rpgc-width-toggle')) {
return;
}
var button = document.createElement('button');
button.id = 'rpgc-width-toggle';
button.type = 'button';
button.addEventListener('click', function () {
var current = localStorage.getItem('rpgc-width-mode') || 'readable';
localStorage.setItem('rpgc-width-mode', current === 'full' ? 'readable' : 'full');
applyWidthMode();
});
document.body.appendChild(button);
applyWidthMode();
}
mw.hook('wikipage.content').add(function () {
addToggle();
});
$(addToggle);
})();