Last edited one month ago
by WikiSysop

MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
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.  
// hide the sidebar navigation.
//document.querySelector('#sb-pri-tgl-btn').style.display = 'none';
//document.querySelector('#sb-pri-tgl-btn').style.display = 'none';
//document.getElementById('sb-pri-tgl-btn').remove();
//document.getElementById('sb-pri-tgl-btn').remove();


// Function to convert Blue spice iframe to real iframes
function convertMediaWikiIframesToReal() {


    // Look for paragraphs that contain escaped iframe tags


// Function to convert MediaWiki processed iframe text to real iframes
    let paragraphs = document.querySelectorAll('p');
function convertMediaWikiIframesToReal() {
 
  // Look for paragraphs that contain escaped iframe tags
    for (let i = 0; i < paragraphs.length; i++) {
  var paragraphs = document.querySelectorAll('p');
 
 
        let paragraph = paragraphs[i];
  for (var i = 0; i < paragraphs.length; i++) {
 
    var paragraph = paragraphs[i];
        let 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
 
      var links = paragraph.querySelectorAll('a.external');
 
     
            // Find any links inside this iframe text
      if (links.length > 0) {
            let links = paragraph.querySelectorAll('a.external');
        // Use the href from the first link as our iframe src
 
        var url = links[0].href;
            if (links.length > 0) {
       
 
        // Create an actual iframe element
                // Use the href from the first link as our iframe src
        var iframe = document.createElement('iframe');
                let url = links[0].href;
        iframe.src = url;
 
        iframe.width = "100%";
                // Create an actual iframe element
        iframe.height = "1000px";
                let iframe = document.createElement('iframe');
        iframe.style.border = "none";
                iframe.src = url;
       
                iframe.width = "100%";
        // Replace the paragraph with the iframe
                iframe.height = "1000px";
        if (paragraph.parentNode) {
                iframe.style.border = "none";
          paragraph.parentNode.replaceChild(iframe, paragraph);
 
          console.log('Converted MediaWiki iframe to real iframe with URL: ' + url);
 
                // 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
    let titleSection = document.querySelector('#title-section');
 
    // We look for this tag in the #title-section <span className="mw-page-title-main">Rt-search</span>
    let pageTitle = titleSection.querySelector('span.mw-page-title-main');
    if (pageTitle && pageTitle.textContent === 'Rt-search') {
        titleSection.style.display = 'none';
 
        // now we hide the form #bs-extendedsearch-box
        let searchBox = document.querySelector('#bs-extendedsearch-box');
        searchBox.style.display = 'none';
 
    }
 
}
}


// Call the function when the page is loaded
// page load
if (document.readyState === 'loading') {
if (document.readyState === 'loading') {
  document.addEventListener('DOMContentLoaded', convertMediaWikiIframesToReal);
    document.addEventListener('DOMContentLoaded', convertMediaWikiIframesToReal);
} else {
} else convertMediaWikiIframesToReal();
  // If the page is already loaded
  convertMediaWikiIframesToReal();
}

Revision as of 22:51, 19 March 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.');

        }

    });

});

//	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 convertMediaWikiIframesToReal() {

    // Look for paragraphs that contain escaped iframe tags

    let paragraphs = document.querySelectorAll('p');

    for (let i = 0; i < paragraphs.length; i++) {

        let paragraph = paragraphs[i];

        let 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
            let links = paragraph.querySelectorAll('a.external');

            if (links.length > 0) {

                // Use the href from the first link as our iframe src
                let url = links[0].href;

                // Create an actual iframe element
                let iframe = document.createElement('iframe');
                iframe.src = url;
                iframe.width = "100%";
                iframe.height = "1000px";
                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
    let titleSection = document.querySelector('#title-section');

    // We look for this tag in the #title-section <span className="mw-page-title-main">Rt-search</span>
    let pageTitle = titleSection.querySelector('span.mw-page-title-main');
    if (pageTitle && pageTitle.textContent === 'Rt-search') {
        titleSection.style.display = 'none';

        // now we hide the form #bs-extendedsearch-box
        let searchBox = document.querySelector('#bs-extendedsearch-box');
        searchBox.style.display = 'none';

    }

}

// page load
if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', convertMediaWikiIframesToReal);
} else convertMediaWikiIframesToReal();