MediaWiki:Gadget-ZoomViewer.js

From wikishia

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/*global $, mw*/
/*jshint curly:false, boss:true */

if ( mw.config.get('wgNamespaceNumber') === 6 && mw.config.get('wgAction') === 'view' && !mw.util.getParamValue('diff')) {
  $(document).ready(
    function () {
      'use strict';

      // get page name and data on the image
      var name = mw.config.get('wgPageName').replace( /_/g, ' ' )
        , id = $('#file img[alt=\'' + name.replace( /'/g, '\\\'' ) + '\']').data();
    
      // check if the image is below 2MP
      if (!id) { return; } 
      var p = id.fileHeight * id.fileWidth;
      if( p < 2*1024*1024 ) return;
      
      // build ZoomViewer links
      var links = $("<span>", { id: "ZoomViewerLinks", style: "white-space:nowrap; display:inline-block;" })
        , fileName = name.match(/File:(.+\.jpe?g)/i);
      // only operate on JPG images
      if (!fileName) { return; }
      var url = "https://zoomviewer.toolforge.org/index.php?f=" + encodeURIComponent( fileName[1] )
        , link = $("<a>", { href: url + "&flash=no", text: "ZoomViewer" });
      links.append("; ", link);
      $('.fileInfo').after(links);
    }
  );
}