Last edited one month ago
by WikiSysop

MediaWiki:Common.js: Difference between revisions

No edit summary
Tag: Reverted
No edit summary
Tag: Manual revert
Line 100: Line 100:
function initializeWhenReady() {
function initializeWhenReady() {
     // Try immediate execution
     // Try immediate execution
     //convertMediaWikiIframesToReal();
     convertMediaWikiIframesToReal();
      
      
     // Also set up additional fallbacks
     // Also set up additional fallbacks
     //setTimeout(convertMediaWikiIframesToReal, 500);
     setTimeout(convertMediaWikiIframesToReal, 500);
     //setTimeout(convertMediaWikiIframesToReal, 1000);
     setTimeout(convertMediaWikiIframesToReal, 1000);
}
}


// Multiple event listeners for different loading states
// Multiple event listeners for different loading states
if (document.readyState === 'loading') {
if (document.readyState === 'loading') {
     //document.addEventListener('DOMContentLoaded', initializeWhenReady);
     document.addEventListener('DOMContentLoaded', initializeWhenReady);
} else if (document.readyState === 'interactive') {
} else if (document.readyState === 'interactive') {
     // DOM is loaded but resources might still be loading
     // DOM is loaded but resources might still be loading
     //initializeWhenReady();
     initializeWhenReady();
} else {
} else {
     // Document is fully loaded
     // Document is fully loaded
     //initializeWhenReady();
     initializeWhenReady();
}
}


// Also try when the window is fully loaded
// Also try when the window is fully loaded
// window.addEventListener('load', convertMediaWikiIframesToReal);
window.addEventListener('load', convertMediaWikiIframesToReal);

Revision as of 18:31, 23 May 2025

mw.loader.using('mediawiki.user').then(function () {
    mw.user.getGroups().then(function (groups) {
        console.log('User groups:', groups);
        if (groups.includes('sysop')) {
            console.log('User is an administrator.');
        }
    });
});

// Function to convert Blue spice iframe to real iframes
function convertMediaWikiIframesToReal() {
    // Look for paragraphs that contain escaped iframe tags
    var paragraphs = document.querySelectorAll('p');
    for (var i = 0; i < paragraphs.length; i++) {
        var paragraph = paragraphs[i];
        var content = paragraph.innerHTML;
        // Check if this paragraph contains an escaped iframe
        if (content.indexOf('&lt;iframe') !== -1 && content.indexOf('&lt;/iframe&gt;') !== -1) {
            // Find any links inside this iframe text
            var links = paragraph.querySelectorAll('a.external');

            if (links.length > 0) {
                // Use the href from the first link as our iframe src
                var url = links[0].href;

                // Create an actual iframe element
                var iframe = document.createElement('iframe');
                iframe.src = url;
                iframe.width = "100%";
                iframe.height = "2400px";
                iframe.style.border = "none";

                // Replace the paragraph with the iframe
                if (paragraph.parentNode) {
                    paragraph.parentNode.replaceChild(iframe, paragraph);
                    console.log('Converted MediaWiki iframe to real iframe with URL: ' + url);
                }
            }
        }
    }

    // Now hide the #title-section - with better error handling
    var titleSection = document.querySelector('#title-section');
    
    if (!titleSection) {
        console.log('title-section not found, retrying in 100ms...');
        setTimeout(convertMediaWikiIframesToReal, 100);
        return;
    }

    console.log('Found title-section:', titleSection);
    
    // Look for the correct page title element - it's an h1 with id "firstHeading"
    var pageTitle = document.querySelector('#firstHeading');
    
    if (pageTitle) {
        console.log('Found page title:', pageTitle.textContent);
        
        if (pageTitle.textContent.trim() === 'Rt-search') {
            console.log('Hiding title section for Rt-search page');
            titleSection.style.display = 'none';

            // Now we hide the form #bs-extendedsearch-box
            var searchBox = document.querySelector('#bs-extendedsearch-box');
            if (searchBox) {
                searchBox.style.display = 'none';
                console.log('Hidden search box');
            } else {
                console.log('Search box not found');
            }

            // Make the background grey
            var body = document.querySelector('body');
            if (body) {
                body.style.backgroundColor = '#e0e0e0';
                console.log('Set body background color');
            }

            // Now we hide the aftercontent
            var afterContent = document.querySelector('#aftercontent');
            if (afterContent) {
                afterContent.style.display = 'none';
                console.log('Hidden aftercontent');
            }
            
            var main = document.querySelector('#main');
            if (main) {
                main.style.backgroundColor = '#e0e0e0';
                console.log('Set main background color');
            }
        } else {
            console.log('Page title is not Rt-search, it is:', pageTitle.textContent.trim());
        }
    } else {
        console.log('Page title element not found');
    }
}

// Enhanced page load handling with multiple fallbacks
function initializeWhenReady() {
    // Try immediate execution
    convertMediaWikiIframesToReal();
    
    // Also set up additional fallbacks
    setTimeout(convertMediaWikiIframesToReal, 500);
    setTimeout(convertMediaWikiIframesToReal, 1000);
}

// Multiple event listeners for different loading states
if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', initializeWhenReady);
} else if (document.readyState === 'interactive') {
    // DOM is loaded but resources might still be loading
    initializeWhenReady();
} else {
    // Document is fully loaded
    initializeWhenReady();
}

// Also try when the window is fully loaded
window.addEventListener('load', convertMediaWikiIframesToReal);