User:Opencooper/imageRatio.js

Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
// Show an upload's aspect ratio in the file history

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();