MediaWiki:Common.js: Difference between revisions

From RPG Continuum Wiki
Jump to navigation Jump to search
Created page with "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..."
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
(function () {


(function () {
if (new URLSearchParams(window.location.search).get('embed') === '1') {
    function applyWidthMode() {
    document.body.classList.add('rpgc-embed');
        var mode = localStorage.getItem('rpgc-width-mode') || 'readable';
}


        document.body.classList.remove('rpgc-readable-width', 'rpgc-full-width');
function applyWidthMode() {
    var narrowWindow = window.matchMedia('(max-width: 950px)').matches;
    var mode = localStorage.getItem('rpgc-width-mode') || 'readable';


        if (mode === 'full') {
    document.body.classList.remove(
            document.body.classList.add('rpgc-full-width');
        'rpgc-readable-width',
         } else {
        'rpgc-full-width',
            document.body.classList.add('rpgc-readable-width');
         'rpgc-narrow-width'
        }
    );


         var button = document.getElementById('rpgc-width-toggle');
    if (narrowWindow) {
         if (button) {
         document.body.classList.add('rpgc-narrow-width');
             button.textContent = mode === 'full' ? 'Readable width' : 'Full width';
    } else {
         }
         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() {
     function addToggle() {
         if (document.getElementById('rpgc-width-toggle')) {
         if (document.getElementById('rpgc-width-toggle')) return;
            return;
 
         }
        var title = document.querySelector('.firstHeading, .mw-first-heading');
         if (!title) return;


         var button = document.createElement('button');
         var button = document.createElement('button');
Line 34: Line 47:
         });
         });


         document.body.appendChild(button);
         title.appendChild(button);
         applyWidthMode();
         applyWidthMode();
     }
     }
    mw.hook('wikipage.content').add(function () {
        addToggle();
    });


     $(addToggle);
     $(addToggle);
    mw.hook('wikipage.content').add(addToggle);
window.addEventListener('resize', applyWidthMode);
})();
})();

Latest revision as of 05:23, 11 July 2026

(function () {

if (new URLSearchParams(window.location.search).get('embed') === '1') {
    document.body.classList.add('rpgc-embed');
}

function applyWidthMode() {
    var narrowWindow = window.matchMedia('(max-width: 950px)').matches;
    var mode = localStorage.getItem('rpgc-width-mode') || 'readable';

    document.body.classList.remove(
        'rpgc-readable-width',
        'rpgc-full-width',
        'rpgc-narrow-width'
    );

    if (narrowWindow) {
        document.body.classList.add('rpgc-narrow-width');
    } else {
        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);
window.addEventListener('resize', applyWidthMode);
})();