Jump to content

User:Macaw*/noRefListAlert.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Macaw* (talk | contribs) at 12:47, 5 May 2025 (change formatting of alert). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
(function() {
    var hasReflist = false;
    var hasReferences = false;

    var ns = mw.config.get('wgNamespaceNumber');
    var isArticleNamespace = ns === 0;
    var isDraftNamespace = ns === 118;
    var isValidNamespace = isArticleNamespace || isDraftNamespace;

    if (document.body.innerHTML.includes('{{reflist}}')) {
        hasReflist = true;
    }

    if (document.body.innerHTML.includes('<references')) {
        hasReferences = true;
    }

    if (!hasReflist && !hasReferences && isValidNamespace) {
        var warningMessage = document.createElement('div');
        warningMessage.style.backgroundColor = '#ffcc00';
        warningMessage.style.color = '#000';
        warningMessage.style.padding = '10px';
        warningMessage.style.fontSize = '16px';
        warningMessage.style.fontWeight = 'bold';
        warningMessage.style.position = 'relative';
        warningMessage.style.zIndex = '1000';
        warningMessage.style.marginBottom = '20px';
        warningMessage.innerHTML = 'Warning: This page does not contain {{reflist}} or <pre><references/></pre>. Please check the references section.';

        var pageTitleElement = document.getElementById('firstHeading').previousElementSibling;
        if (pageTitleElement) {
            pageTitleElement.parentNode.insertBefore(warningMessage, pageTitleElement.nextSibling);
        }
    }
})();