User:Krinkle/Scripts/TinEye.js

From Meta, a Wikimedia project coordination wiki

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.
/**
 * https://meta.wikimedia.org/wiki/User:Krinkle/Scripts/TinEye
 *
 * @revision 2015-01-23
 * @license http://krinkle.mit-license.org/
 * @author Timo Tijhof, 2010–2015
 */
$.when(mw.loader.using('mediawiki.util'), $.ready).done(function () {
	var conf = mw.config.get([
		'wgNamespaceNumber',
		'wgAction'
	]);
	if (conf.wgNamespaceNumber !== 6 || !document.getElementById('file')) return;
	if (conf.wgAction !== 'view' && wgAction !== 'purge') return;
	var imgs = $('#file img');
	if (!imgs.length) return; // No preview image
	mw.util.addPortletLink(
		'p-cactions',
		'http://tineye.com/search?url=' + encodeURIComponent(imgs[0].src),
		'TinEye',
		'ca-tineye'
	);
});