User:Ikan Kekek/vector.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
//
 // 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( $('').text(' (' + ((w*h)/1e6).toFixed(2) + ' Megapixel)' ) );
  }
 }
 if( wgAction == 'view' && wgNamespaceNumber == 6 ) $(document).ready(calculateMegapixels);