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 14:37, 5 May 2025 (unclose). 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) {
    if (mw.config.get('wgAction') !== 'view') {
        return;
    }
    if (mw.config.get('wgIsRedirect')) {
        return;
    }
    if (mw.config.get('wgArticleId') === 0) {
        return;
    }
    
    var ns = mw.config.get('wgNamespaceNumber');
    var title = mw.config.get('wgTitle').replace(/_/g, ' ');
    if (title === 'Main Page') {
        return;
    }
  
    var isValidNamespace = (ns === 0 || ns === 118);
  
    
    var rawHTML = $content.html();
    var hasWikitextRefMarker = rawHTML.indexOf('{{reflist') !== -1 ||
                               rawHTML.indexOf('<references') !== -1;
  
    if (isValidNamespace && !(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.';
  
        var $firstHeading = $('#firstHeading');
        if ($firstHeading.length) {
            $firstHeading.after(warningMessage);
        }
    }
});