MediaWiki:Common.js: Difference between revisions

OMNIVERSE
No edit summary
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
// Make image links open the full resolution image directly
// Simpler: Make image links open the full resolution image
$(document).ready(function() {
$('.mw-parser-output a.image').each(function() {
    $('.mw-parser-output a.image').each(function() {
    var $img = $(this).find('img');
        var $link = $(this);
    if ($img.length) {
        var $img = $link.find('img');
        var src = $img.attr('src');
       
        // Remove thumbnail path to get full image
        if ($img.length) {
        var fullSrc = src.replace(/\/thumb\//, '/').replace(/\/\d+px-[^/]+$/, '');
            var src = $img.attr('src');
        $(this).attr('href', fullSrc);
           
     }
            // 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.attr('href', fullSrc);
        }
     });
});
});

Revision as of 02:59, 25 January 2026

// Make image links open the full resolution image directly
$(document).ready(function() {
    $('.mw-parser-output a.image').each(function() {
        var $link = $(this);
        var $img = $link.find('img');
        
        if ($img.length) {
            var src = $img.attr('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.attr('href', fullSrc);
        }
    });
});