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 23:42, 9 June 2024. 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("1");}
    	var res = document.getElementsByClassName("fileInfo")[0].innerHTML.replaceAll(/ pixels.*/g, "").replaceAll("(","").replaceAll("SVG file, nominally","").replaceAll(" ","").split("×");
    	if(debug == 1) {console.log("2");}
    	// should produce [width, height].
    	if(debug == 1) {console.log("3");}
    	var size = int((int(res[0])/int(res[1])) * 301);
    	if(debug == 1) {console.log("4");}
    	
    	// Put this in a div.
    	var newDiv = document.createElement('div');
    	if(debug == 1) {console.log("5");}
    	newDiv.class = "signpost-filetools";
    	if(debug == 1) {console.log("6");}
    	newDiv.innerHTML = String(size);
    	if(debug == 1) {console.log("7");}
    	document.getElementsByClassName("mw-filepage-resolutioninfo")[0].appendChild(newDiv);
    	if(debug == 1) {console.log("8");}

    } // if page title has "File:" in it
} );