Last edited one month ago
by WikiSysop

MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
 
(19 intermediate revisions by the same user not shown)
Line 8: Line 8:
});
});


// hide the sidebar navigation.
// Function to convert Blue spice iframe to real iframes
//document.querySelector('#sb-pri-tgl-btn').style.display = 'none';
function convertMediaWikiIframesToReal() {
//document.getElementById('sb-pri-tgl-btn').remove();
    // 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";


// Function to convert MediaWiki processed iframe text to real iframes
                // Replace the paragraph with the iframe
function convertMediaWikiIframesToReal() {
                if (paragraph.parentNode) {
  // Look for paragraphs that contain escaped iframe tags
                    paragraph.parentNode.replaceChild(iframe, paragraph);
  var paragraphs = document.querySelectorAll('p');
                    console.log('Converted MediaWiki iframe to real iframe with URL: ' + url);
 
                }
  for (var i = 0; i < paragraphs.length; i++) {
            }
     var paragraph = paragraphs[i];
        }
     var content = paragraph.innerHTML;
    }
 
    // 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');
      
      
     // Check if this paragraph contains an escaped iframe
     if (pageTitle) {
    if (content.indexOf('&lt;iframe') !== -1 && content.indexOf('&lt;/iframe&gt;') !== -1) {
        console.log('Found page title:', pageTitle.textContent);
     
      // 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
         if (pageTitle.textContent.trim() === 'Rt-search') {
        var iframe = document.createElement('iframe');
            console.log('Hiding title section for Rt-search page');
        iframe.src = url;
            titleSection.style.display = 'none';
        iframe.width = "100%";
 
        iframe.height = "500px";
            // Now we hide the form #bs-extendedsearch-box
        iframe.style.border = "none";
            var searchBox = document.querySelector('#bs-extendedsearch-box');
       
            if (searchBox) {
        // Replace the paragraph with the iframe
                searchBox.style.display = 'none';
        if (paragraph.parentNode) {
                console.log('Hidden search box');
          paragraph.parentNode.replaceChild(iframe, paragraph);
            } else {
          console.log('Converted MediaWiki iframe to real iframe with URL: ' + url);
                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');
     }
     }
  }
}
}


// Call the function when the page is loaded
// 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') {
if (document.readyState === 'loading') {
  document.addEventListener('DOMContentLoaded', convertMediaWikiIframesToReal);
    document.addEventListener('DOMContentLoaded', initializeWhenReady);
} else if (document.readyState === 'interactive') {
    // DOM is loaded but resources might still be loading
    initializeWhenReady();
} else {
} else {
  // If the page is already loaded
    // Document is fully loaded
  convertMediaWikiIframesToReal();
    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);