User:Opencooper/imageRatio.js

// Show an upload's aspect ratio in the file history
// License: CC0
// [[Category:Commons user scripts|imageRatio]]

function getRatio() {
    // If we're not reading an article, do nothing
    if (!(mw.config.get("wgAction") === "view"
          && mw.config.get("wgIsArticle")
          && mw.config.get("wgPageName") !== "Main_Page")) {
        return;
    }

    $(".filehistory td:nth-child(4)").each(function() {
        var content = $(this).html();
        var dimensions = content.match(/([0-9,]+) × ([0-9,]+)/);
        
        if (dimensions) {
            var width = parseInt(dimensions[1].replace(/,/, ""));
            var height = parseInt(dimensions[2].replace(/,/, ""));

            var ratio = (width / height).toFixed(2);
            $(this).html(content + " [" + ratio + "]");
        } else {
        	return false;
        }
    });
}

getRatio();
Category:Commons user scripts