User:Blurred Lines/common.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
The accompanying .css page for this skin can be added at User:Blurred Lines/common.css. |
/*global mw, jQuery*/
/*jshint curly:false */
jQuery(document).ready(function() {
'use strict';
if (mw.config.get('wgNamespaceNumber') !== 6 || mw.config.get('wgAction') !== "view" || !document.getElementById('file')) return;
var imgs = document.getElementById('file').getElementsByTagName('img');
if (!imgs || imgs.length === 0) return; // No preview image, e.g. for large PNGs
var imageurl = imgs[0].parentNode.href;
if (!imageurl) return; /* This occurs with thumbs of videos for instance */
// For the case of 'Error creating thumbnail: Invalid thumbnail parameters or PNG file with more than 12.5 million pixels'
if (document.getElementById('file').getElementsByTagName('img').length <= 0) return;
if (document.getElementById('file').getElementsByTagName('img')[0].width <= 10000) {
imageurl = document.getElementById('file').getElementsByTagName('img')[0].src; //Image smaller than 10000px 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 + "/10000px-" + imageurl.substring(n);
}
mw.util.addPortletLink('p-cactions', 'https://www.google.com/searchbyimage?image_url=' + encodeURIComponent(imageurl), 'Google Images', 'ca-googleimages', null);
});