Jump to content

User:Tpbradbury/monobook.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Tpbradbury (talk | contribs) at 17:18, 3 June 2024 (update). 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.
// Monobook.js is loading
console.log('Monobook.js is loading');

// HighlightUnreferencedPassages.js is loading
console.log('HighlightUnreferencedPassages.js is loading');

// Document ready
document.addEventListener('DOMContentLoaded', function () {
    console.log('Document ready');

    // Stylesheet added
    console.log('Stylesheet added');

    // highlightUnreferencedPassages function is executed
    console.log('highlightUnreferencedPassages function is executed');

    // Find the mw-content-text element
    var contentText = document.getElementById('mw-content-text');
    if (contentText) {
        console.log('mw-content-text element found');

        // Get all elements to be highlighted
        var elementsToHighlight = contentText.querySelectorAll('.highlight-unreferenced');
        console.log('Total elements found:', elementsToHighlight.length);

        // Find the references section
        var referencesSection = contentText.querySelector('#References, .references');
        var stopHighlighting = false;

        // Iterate through elements to be highlighted
        elementsToHighlight.forEach(function (element) {
            // Stop if the references section is reached
            if (referencesSection && referencesSection.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_FOLLOWING) {
                stopHighlighting = true;
            }

            if (!stopHighlighting) {
                // Highlight unreferenced element
                element.classList.add('highlighted');
                console.log('Highlighted unreferenced element:', element);
            }
        });
    }

    console.log('Highlighting completed');
});