Last edited one month ago
by WikiSysop

Common.js

Revision as of 22:01, 14 March 2025 by WikiSysop (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
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 find text iframes and convert them to real iframes
function convertTextIframesToReal() {
	console.log("convertTextIframesToReal()");
  // Get all elements in the document
  var allElements = document.querySelectorAll('*');
  
  // Look for elements with text content that contains iframe tags
  for (var i = 0; i < allElements.length; i++) {
    var element = allElements[i];
    
    if (element.childNodes && element.childNodes.length > 0) {
      for (var j = 0; j < element.childNodes.length; j++) {
        var node = element.childNodes[j];
        
        // 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();
          
          // Use regex to extract the URL from src attribute
          var srcMatch = /src="([^"]+)"/.exec(text);
          
          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);
          }
        }
      }
    }
  }
}

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