No edit summary |
No edit summary |
||
(15 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.'); | ||
} | } | ||
}); | }); | ||
}); | }); | ||
// 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('<iframe') !== -1 && content.indexOf('</iframe>') !== -1) { | if (content.indexOf('<iframe') !== -1 && content.indexOf('</iframe>') !== -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 = " | 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 - 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; | |||
} | |||
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') { | if (document.readyState === 'loading') { | ||
document.addEventListener('DOMContentLoaded', | 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('<iframe') !== -1 && content.indexOf('</iframe>') !== -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);