MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
(function () { | (function () { | ||
if (new URLSearchParams(window.location.search).get('embed') === '1') { | |||
document.body.classList.add('rpgc-embed'); | |||
} | |||
function applyWidthMode() { | function applyWidthMode() { | ||
var mode = localStorage.getItem('rpgc-width-mode') || 'readable'; | var mode = localStorage.getItem('rpgc-width-mode') || 'readable'; | ||
Latest revision as of 00:09, 5 July 2026
(function () {
if (new URLSearchParams(window.location.search).get('embed') === '1') {
document.body.classList.add('rpgc-embed');
}
function applyWidthMode() {
var mode = localStorage.getItem('rpgc-width-mode') || 'readable';
document.body.classList.remove('rpgc-readable-width', 'rpgc-full-width');
document.body.classList.add(mode === 'full' ? 'rpgc-full-width' : '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 title = document.querySelector('.firstHeading, .mw-first-heading');
if (!title) 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();
});
title.appendChild(button);
applyWidthMode();
}
$(addToggle);
mw.hook('wikipage.content').add(addToggle);
})();