MediaWiki:Common.js: Difference between revisions

OMNIVERSE
No edit summary
No edit summary
Line 1: Line 1:
// Make image links open the full resolution image directly
// Make image links open the full resolution image directly (no jQuery)
$(document).ready(function() {
document.addEventListener('DOMContentLoaded', function() {
     $('.mw-parser-output a.image').each(function() {
     var imageLinks = document.querySelectorAll('.mw-parser-output a.image');
         var $link = $(this);
   
        var $img = $link.find('img');
    imageLinks.forEach(function(link) {
         var img = link.querySelector('img');
          
          
         if ($img.length) {
         if (img) {
             var src = $img.attr('src');
             var src = img.getAttribute('src');
              
              
             // Convert thumbnail URL to full image URL
             // Convert thumbnail URL to full image URL
Line 14: Line 15:
              
              
             // Update the link href
             // Update the link href
             $link.attr('href', fullSrc);
             link.setAttribute('href', fullSrc);
           
            console.log('Changed link from:', link.getAttribute('href'), 'to:', fullSrc);
         }
         }
     });
     });
});
});

Revision as of 03:01, 25 January 2026

// Make image links open the full resolution image directly (no jQuery)
document.addEventListener('DOMContentLoaded', function() {
    var imageLinks = document.querySelectorAll('.mw-parser-output a.image');
    
    imageLinks.forEach(function(link) {
        var img = link.querySelector('img');
        
        if (img) {
            var src = img.getAttribute('src');
            
            // Convert thumbnail URL to full image URL
            // From: /images/thumb/f/fd/Sunny_Meadows.png/300px-Sunny_Meadows.png
            // To: /images/f/fd/Sunny_Meadows.png
            var fullSrc = src.replace(/\/thumb(\/[^\/]+\/[^\/]+\/)(\d+px-)?(.+)$/, '$1$3');
            
            // Update the link href
            link.setAttribute('href', fullSrc);
            
            console.log('Changed link from:', link.getAttribute('href'), 'to:', fullSrc);
        }
    });
});