Last edited one month ago
by WikiSysop

MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
 
(8 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.  
// 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
    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) {




// Function to find text iframes and convert them to real iframes
            // Find any links inside this iframe text
function convertTextIframesToReal() {
            var links = paragraph.querySelectorAll('a.external');
console.log("convertTextIframesToReal()");
 
  // Get all elements in the document
            if (links.length > 0) {
  var allElements = document.querySelectorAll('*');
 
 
                // Use the href from the first link as our iframe src
  // Look for elements with text content that contains iframe tags
                var url = links[0].href;
  for (var i = 0; i < allElements.length; i++) {
 
    var element = allElements[i];
                // Create an actual iframe element
   
                var iframe = document.createElement('iframe');
    if (element.childNodes && element.childNodes.length > 0) {
                iframe.src = url;
      for (var j = 0; j < element.childNodes.length; j++) {
                iframe.width = "100%";
        var node = element.childNodes[j];
                iframe.height = "2400px";
       
                iframe.style.border = "none";
        // Check if this is a text node containing an iframe
 
        if (node.nodeType === 3 && node.textContent.trim().indexOf('<iframe') !== -1) {
 
          var text = node.textContent.trim();
                // Replace the paragraph with the iframe
         
                if (paragraph.parentNode) {
          // Use regex to extract the URL from src attribute
                    paragraph.parentNode.replaceChild(iframe, paragraph);
          var srcMatch = /src="([^"]+)"/.exec(text);
                    console.log('Converted MediaWiki iframe to real iframe with URL: ' + url);
         
                }
          if (srcMatch && srcMatch[1]) {
            }
            var url = srcMatch[1];
           
            // Create a real iframe element with src attribute
            var iframe = document.createElement('iframe');
            iframe.src = url;
           
            // You can add additional attributes as needed
            iframe.width = "100%";
            iframe.height = "500px";
            iframe.style.border = "none";
           
            // Replace the text node with the real iframe
            node.parentNode.replaceChild(iframe, node);
            console.log('Converted iframe with URL: ' + url);
          }
         }
         }
      }
     }
     }
  }
 
    // now hide the #title-section
    var titleSection = document.querySelector('#title-section');
 
    // We look for this tag in the #title-section <span className="mw-page-title-main">Rt-search</span>
    var 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
        var searchBox = document.querySelector('#bs-extendedsearch-box');
        searchBox.style.display = 'none';
 
        // make the background grey
        var body = document.querySelector('body');
        body.style.backgroundColor = '#e0e0e0';
 
        // now we hide the aftercontent
        var afterContent = document.querySelector('#aftercontent');
        afterContent.style.display = 'none';
 
 
        var main = document.querySelector('#main');
        main.style.backgroundColor = '#e0e0e0';
 
    }
 
}
}


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

Latest revision as of 23:49, 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

    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
    var titleSection = document.querySelector('#title-section');

    // We look for this tag in the #title-section <span className="mw-page-title-main">Rt-search</span>
    var 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
        var searchBox = document.querySelector('#bs-extendedsearch-box');
        searchBox.style.display = 'none';

        // make the background grey
        var body = document.querySelector('body');
        body.style.backgroundColor = '#e0e0e0';

        // now we hide the aftercontent
        var afterContent = document.querySelector('#aftercontent');
        afterContent.style.display = 'none';


        var main = document.querySelector('#main');
        main.style.backgroundColor = '#e0e0e0';

    }

}

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