MediaWiki:Gadget-LocatorTool.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.
// Locator-tool code begins, see [[Commons:Locator-tool]] for details.
// For MediaWiki.js docs, see https://doc.wikimedia.org/mediawiki-core/master/js/
(function(mw, $) {

  if (mw.config.get('wgAction') !== 'view') return;

  $(function() {
  	
  	var title = new mw.Title(mw.config.get('wgTitle'), mw.config.get('wgNamespaceNumber'));
  	var titleForUrl = encodeURIComponent(title.toString());
  	var url = 'https://locator-tool.toolforge.org/#/geolocate';
  	if (mw.config.get('wgNamespaceNumber') === 2) {
  		url += '?user=' + titleForUrl;
  	} else if (mw.config.get('wgNamespaceNumber') === 6) {
  		url += '?files=' + titleForUrl;
  	} else if (mw.config.get('wgNamespaceNumber') === 14) {
  		url += '?category=' + titleForUrl;
  	} else {
  		return;
  	}

    mw.util.addPortletLink(
      'p-tb',
      url,
      'Locator-tool',
      't-locator',
      'Geolocate this image'
    );

  });

})(mediaWiki, jQuery);