Jump to content

User:Epicgenius/hiderefs.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
mw.loader.using(['mediawiki.util']).then(function () {
    const link = mw.util.addPortletLink(
        'p-cactions',
        '#',
        'Hide references',
        'ca-hide-references',
        'Hide/show references and maintenance tags'
    );

    if (!link) return;

    let hidden = false;

    link.addEventListener('click', function (event) {
        event.preventDefault();
        hidden = !hidden;

        document.querySelectorAll(
            '.reference, .reflist, .references, .mw-references-wrap, ' +
            'ol.references, sup.reference, .Inline-Template, ' +
            '.ambox, .tmbox, .cmbox, .ombox, .fmbox, ' +
            '.maintenance, .hatnote'
        ).forEach(function (element) {
            element.style.display = hidden ? 'none' : '';
        });

        link.textContent = hidden ? 'Show references' : 'Hide references';
    });
});