User:Chick Bowen/monobook.js

Source: Wikipedia, the free encyclopedia.
<
User:Chick Bowen
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//
// Calculate Megapixels on image pages
//
function calculateMegapixels() {
 var data = $('.fileInfo').text();
 pixel_filter = /([\d,]+) × ([\d,]+)/;
 if(pixel_filter.test(data)) {
  pixel_filter.exec(data);
  var wt = RegExp.$1, ht = RegExp.$2
    , w = parseFloat( wt.replace(/,/,'') )
    , h = parseFloat( ht.replace(/,/,'') );
  $('.fileInfo').append( $('<span></span>').text(' (' + ((w*h)/(1024.0*1024.0)).toFixed(2) + ' Megapixel)' ) );
 }
}
if( wgAction == 'view' && wgNamespaceNumber == 6 ) $(document).ready(calculateMegapixels);