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 13:05, 5 May 2025 (bugfixing). 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.
mw.hook('wikipage.content').add(function($content) {
    var ns = mw.config.get('wgNamespaceNumber');
    var isValidNamespace = (ns === 0 || ns === 118);

    var hasRenderedReferences = $content.find('.reflist').length > 0 ||
                                $content.find('.mw-references-wrap').length > 0 ||
                                $content.find('ol.references').length > 0;

    var hasReferencesHeader = false;
    $content.find('h2, h3').each(function() {
        if ($(this).text().trim().toLowerCase().indexOf('references') !== -1) {
            hasReferencesHeader = true;
            return false;
        }
    });

    var rawHTML = $content.html();
    var hasWikitextRefMarker = rawHTML.indexOf('{{reflist}}') !== -1 ||
                               rawHTML.indexOf('<references') !== -1;

    if (isValidNamespace && !(hasRenderedReferences || hasReferencesHeader || hasWikitextRefMarker)) {
        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 a references section. Please check the references section.';

        var $firstHeading = $('#firstHeading');
        if ($firstHeading.length) {
            $firstHeading.after(warningMessage);
        }
    }
});