Jump to content

User:JPxG/signpost-filetools.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by JPxG (talk | contribs) at 02:26, 10 June 2024 (hmmmm -- this isnt producing the result i want lol -- 602 is a very odd number for the things im testing it on -- perhaps it is doing int math instead of float?). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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 )) {
    	var debug = 1;
    	if(debug == 1) {console.log("starting script");}
    	var res = 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]);
    	res[1] = parseFloat(res[1]);
    	var size = parseInt((res[0]/res[1]) * 301.0);
		
		var filename = document.getElementById("firstHeading").innerHTML;
		var credits  = document.getElementById("fileinfotpl_aut").nextSibling.nextSibling.innerHTML.replaceAll("\n","")
		var license  = document.getElementsByClassName("licensetpl_short")[0].innerHTML;
		var scaling  = String(size);
	
		var template = ""
		template +=   " |piccyfilename      = " + filename;
		template += "\n |piccy-credits      = " + credits;
		template += "\n |piccy-license      = " + license;
		template += "\n |piccy-xoffset      = " + "0";
		template += "\n |piccy-yoffset      = " + "0";
		template += "\n |piccy-scaling      = " + scaling;
		template += "\n}}";
	
    	// Put this in a div.
    	var newDiv = document.createElement('pre');
    	newDiv.class = "signpost-filetools";
    	newDiv.innerHTML = template;
    	if(debug == 1) {console.log("appending to resolutioninfo");}
    	document.getElementsByClassName("mw-filepage-resolutioninfo")[0].appendChild(newDiv);
    } // if page title has "File:" in it
} );