MediaWiki:Common.js: Difference between revisions

OMNIVERSE
No edit summary
No edit summary
Line 1: Line 1:
console.log('Common.js is loading!');
console.log('Common.js is loading!');


// Make image links open the full resolution image directly (no jQuery)
// Use a later event to ensure page is fully loaded
document.addEventListener('DOMContentLoaded', function() {
if (document.readyState === 'loading') {
     console.log('DOMContentLoaded fired!');
    document.addEventListener('DOMContentLoaded', changeImageLinks);
} else {
    changeImageLinks();
}
 
function changeImageLinks() {
     console.log('changeImageLinks function called!');
      
      
     var imageLinks = document.querySelectorAll('.mw-parser-output a.image');
    // Try multiple selectors
     var imageLinks = document.querySelectorAll('a.image, .mw-parser-output a.image, a[class*="image"]');
     console.log('Found ' + imageLinks.length + ' image links');
     console.log('Found ' + imageLinks.length + ' image links');
      
      
     imageLinks.forEach(function(link) {
    if (imageLinks.length === 0) {
        console.log('No image links found. Trying alternative selector...');
        imageLinks = document.querySelectorAll('a[href*="/File:"]');
        console.log('Found ' + imageLinks.length + ' File: links');
    }
   
     imageLinks.forEach(function(link, index) {
        console.log('Processing link ' + index + ':', link.href);
         var img = link.querySelector('img');
         var img = link.querySelector('img');
          
          
         if (img) {
         if (img) {
             var src = img.getAttribute('src');
             var src = img.getAttribute('src');
            console.log('Image src:', src);
             var fullSrc = src.replace(/\/thumb(\/[^\/]+\/[^\/]+\/)(\d+px-)?(.+)$/, '$1$3');
             var fullSrc = src.replace(/\/thumb(\/[^\/]+\/[^\/]+\/)(\d+px-)?(.+)$/, '$1$3');
             link.setAttribute('href', fullSrc);
             link.setAttribute('href', fullSrc);
Line 18: Line 33:
         }
         }
     });
     });
});
}

Revision as of 03:09, 25 January 2026

console.log('Common.js is loading!');

// Use a later event to ensure page is fully loaded
if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', changeImageLinks);
} else {
    changeImageLinks();
}

function changeImageLinks() {
    console.log('changeImageLinks function called!');
    
    // Try multiple selectors
    var imageLinks = document.querySelectorAll('a.image, .mw-parser-output a.image, a[class*="image"]');
    console.log('Found ' + imageLinks.length + ' image links');
    
    if (imageLinks.length === 0) {
        console.log('No image links found. Trying alternative selector...');
        imageLinks = document.querySelectorAll('a[href*="/File:"]');
        console.log('Found ' + imageLinks.length + ' File: links');
    }
    
    imageLinks.forEach(function(link, index) {
        console.log('Processing link ' + index + ':', link.href);
        var img = link.querySelector('img');
        
        if (img) {
            var src = img.getAttribute('src');
            console.log('Image src:', src);
            var fullSrc = src.replace(/\/thumb(\/[^\/]+\/[^\/]+\/)(\d+px-)?(.+)$/, '$1$3');
            link.setAttribute('href', fullSrc);
            console.log('Changed link to:', fullSrc);
        }
    });
}