User:Ainz Ooal Gown/googleimages-tineye.js
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.
Documentation for this user script can be added at User:Ainz Ooal Gown/googleimages-tineye. |
$(function () {
'use strict';
if (mw.config.get('wgNamespaceNumber') !== 6 || mw.config.get('wgAction') !== "view" || !document.getElementById('file'))
return;
var img = document.getElementById('file').getElementsByTagName('img');
if (!img || !img.length)
return; // No preview image, e.g. for large PNGs
img = img[0];
var imgURL = img.parentNode.href;
if (!imgURL)
return; // This occurs with thumbs of videos/sounds for instance
if (img.width <= 300)
imgURL = img.src; // Image smaller than 300px width
else { // Get thumb url
var n = imgURL.indexOf("/commons/") + 9;
imgURL = imgURL.substr(0, n) + "thumb/" + imgURL.substr(n);
n = imgURL.lastIndexOf('/') + 1;
imgURL += "/300px-" + imgURL.substring(n);
if (!imgURL.slice(-3).indexOf("svg"))
imgURL += ".png";
}
mw.util.addPortletLink('p-cactions', 'https://www.google.com/searchbyimage?image_url=' + encodeURIComponent(imgURL), 'Google Images', 'ca-googleimages', null).children[0].target = '_blank';
mw.util.addPortletLink('p-cactions', 'https://tineye.com/search?url=' + encodeURIComponent(imgURL) + '&sort=size&order=desc', 'TinEye', 'ca-tineye', null).children[0].target = '_blank';
});