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.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$(function(){if((window.___location.href.indexOf("File:")>=0)||(window.___location.href.indexOf("File%3A")>=0)){vardebug=1;if(debug==1){console.log("starting script");}varres=document.getElementsByClassName("fileInfo")[0].innerHTML.replaceAll(/ pixels.*/g,"").replaceAll("(","").replaceAll("SVG file, nominally","").replaceAll(" ","").split("×");// should produce [width, height].if(debug==1){console.log("width/height are");}if(debug==1){console.log(res);}res[0]=parseFloat(res[0].replaceAll(",",""));res[1]=parseFloat(res[1].replaceAll(",",""));if(debug==1){console.log("parseFloated, those are:");}if(debug==1){console.log(res);}if(debug==1){console.log("0/1 is:");}if(debug==1){console.log(res[0]/res[1]);}if(debug==1){console.log("* 301 is:");}if(debug==1){console.log((res[0]/res[1])*300.0);}varsize=parseInt(Math.ceil((res[0]/res[1])*300.0));if(size<300){size=300;}// If it's portrait orientation, a width below 300 will letterbox it the OTHER way!varfilename=document.getElementById("firstHeading").textContent;varcredit;varlicense;try{credits=document.getElementById("fileinfotpl_aut").nextSibling.nextSibling.textContent;}catch(e){credits="?";}try{license=document.getElementsByClassName("licensetpl_short")[0].innerHTML;}catch(e){license="?";}varscaling=String(size);// Clean various crud out of these scraped attributesfilename=filename.replaceAll("[edit]","");if(credits.indexOf("commons-creator-table")!==-1){// This being in the string means that instead of an author name, we scooped up a huge template// If this happens, we should just start over and scrape the field properly from said template.credits=document.getElementById("creator").textContent;}credits=credits.replaceAll("\n","");credits=credits.replaceAll("(talk)","");credits=credits.replaceAll("(Uploads)","");credits=credits.replaceAll("Unknown authorUnknown author","Unknown author");if(credits=="Unknown author"){credits="anon.";}if(credits=="unknown author"){credits="anon.";}if(credits=="Anonymous"){credits="anon.";}if(credits=="anonymous"){credits="anon.";}license=license.replaceAll("Public ___domain","PD");license=license.replaceAll("No restrictions","PD");xoffset=0;yoffset=0;if(size>300){xoffset=parseInt((size-300)/2);}if(size==300){height=res[1]/(res[0]/300);yoffset=parseInt((height-300)/2);}vartemplate=""template+=" |piccyfilename = "+String(filename);template+="\n |piccy-credits = "+String(credits);template+="\n |piccy-license = "+String(license);template+="\n |piccy-xoffset = "+String(xoffset);template+="\n |piccy-yoffset = "+String(yoffset);template+="\n |piccy-scaling = "+String(scaling);template+="\n}}";// Put this in a details-summary block so you can get to it from the file page.vardetails=document.createElement('details');varsummary=document.createElement('summary');summary.textContent="Use in Signpost template";// This works on Wikipedia but not Commons -- for Commons you have to use a pre// var syntaxhighlight = document.createElement('syntaxhighlight');// syntaxhighlight.setAttribute("lang", "wikitext");varsyntaxhighlight=document.createElement('pre');syntaxhighlight.textContent=template;details.appendChild(summary);details.appendChild(syntaxhighlight);details.class="signpost-filetools";if(debug==1){console.log("appending to resolutioninfo");}document.getElementsByClassName("mw-filepage-resolutioninfo")[0].appendChild(details);}// if page title has "File:" in it});