MediaWiki:Gadget-Tineye.js

$(document).ready(function {	if (wgNamespaceNumber !== 6 || wgAction !== "view") return;	var $link = $('.fullImageLink a[class!="mw-thumbnail-link"]'),		$image = $link.find('img'),		imageurl = $link.attr('href');

if (imageurl === undefined || $image.length < 1) return; // No preview image, e.g. for large PNGs or video

if ($image.width <= 300) { imageurl = $image.attr('src'); //Image smaller than 300px width } else { //Get thumb url var n = imageurl.indexOf("/commons/"); imageurl = imageurl.substring(0, n + ("/commons/").length) + "thumb/" + imageurl.substring(n + ("/commons/").length);

n = imageurl.lastIndexOf('/') + 1; imageurl = imageurl + "/300px-" + imageurl.substring(n); }	if (imageurl.substring(0, 2) == '//') // Protocol relative url, tineye fails with "Whoops! It looks like you are searching for keywords instead of pointing TinEye to a specific image." imageurl = 'http:' + imageurl; mw.util.addPortletLink('p-cactions', 'http://tineye.com/search?url=' + encodeURIComponent(imageurl) + '&sort=size&order=desc', 'TinEye', 'ca-tineye', null); });