Last edited one month ago
by WikiSysop

MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
mw.loader.using('mediawiki.user').then(function () {
mw.loader.using('mediawiki.user').then(function () {
     mw.user.getGroups().then(function (groups) {
     mw.user.getGroups().then(function (groups) {
         console.log('User groups:', groups);
         console.log('User groups:', groups);
         if (groups.includes('sysop')) {
         if (groups.includes('sysop')) {
             console.log('User is an administrator.');
             console.log('User is an administrator.');
         }
         }
     });
     });
});
});
// hide the sidebar navigation.
//document.querySelector('#sb-pri-tgl-btn').style.display = 'none';
//document.getElementById('sb-pri-tgl-btn').remove();


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


             if (links.length > 0) {
             if (links.length > 0) {
                 // Use the href from the first link as our iframe src
                 // Use the href from the first link as our iframe src
                 var url = links[0].href;
                 var url = links[0].href;
Line 50: Line 28:
                 iframe.src = url;
                 iframe.src = url;
                 iframe.width = "100%";
                 iframe.width = "100%";
                 iframe.height = "1200px";
                 iframe.height = "2400px";
                 iframe.style.border = "none";
                 iframe.style.border = "none";


                 // Replace the paragraph with the iframe
                 // Replace the paragraph with the iframe
Line 63: Line 40:
     }
     }


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


     // We look for this tag in the #title-section <span className="mw-page-title-main">Rt-search</span>
    console.log('Found title-section:', titleSection);
     var pageTitle = titleSection.querySelector('span.mw-page-title-main');
   
    if (pageTitle && pageTitle.textContent === 'Rt-search') {
     // Look for the correct page title element - it's an h1 with id "firstHeading"
        titleSection.style.display = 'none';
     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
            // Now we hide the form #bs-extendedsearch-box
        var searchBox = document.querySelector('#bs-extendedsearch-box');
            var searchBox = document.querySelector('#bs-extendedsearch-box');
        searchBox.style.display = 'none';
            if (searchBox) {
 
                searchBox.style.display = 'none';
        // make the background grey
                console.log('Hidden search box');
        var body = document.querySelector('body');
            } else {
        body.style.backgroundColor = '#e0e0e0';
                console.log('Search box not found');
 
            }
 
        // now we hide the aftercontent
        var afterContent = document.querySelector('#aftercontent');
        afterContent.style.display = 'none';


            // 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');
            }
           
            // Hide the access restriction alert
            var alertContainer = document.querySelector('#mwstake-alert-container');
            if (alertContainer) {
                alertContainer.style.display = 'none';
                console.log('Hidden access restriction alert');
            }
           
            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);
}
}


// page load
// Multiple event listeners for different loading states
if (document.readyState === 'loading') {
if (document.readyState === 'loading') {
     document.addEventListener('DOMContentLoaded', convertMediaWikiIframesToReal);
     document.addEventListener('DOMContentLoaded', initializeWhenReady);
} else convertMediaWikiIframesToReal();
} 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);

Latest revision as of 18:42, 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');
            }
            
            // Hide the access restriction alert
            var alertContainer = document.querySelector('#mwstake-alert-container');
            if (alertContainer) {
                alertContainer.style.display = 'none';
                console.log('Hidden access restriction alert');
            }
            
            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);