User:NguoiDungKhongDinhDanh/script-imageres.js

// Originally by Alex 21 $(document.getElementsByClassName("fileInfo")).ready(function {	// Filenamespace only	if (mw.config.get("wgNamespaceNumber") !== 6) return;	// Get file information: height and width	var fileInfo = document.getElementsByClassName("fileInfo")[0];	if(!fileInfo) return;	var height_width = fileInfo.innerHTML.match(/([\d\.,]+) ?× ?([\d\.,]+)/);

// With the height and width, calculate the total pixel count var width = parseInt(height_width[1].replace(/(\.|,)/g,'')); var height = parseInt(height_width[2].replace(/(\.|,)/g,'')); var total_pixels = height*width;

// Colour coding the results var colour_start = ""; var colour_end = "";

// Add the total pixel count after the initial dimensions fileInfo.innerHTML = fileInfo.innerHTML.replace(/([\d\.,]+) ?× ?([\d\.,]+)/,			number_format(width) + " × " + number_format(height) + " = " + colour_start + number_format(total_pixels) + colour_end + " ");

// I_hate_those_underscores. $(".internal").text($(".internal").text.replace(/_/g, " "));

// Add commas to values over 1000. function number_format(x) { return x.toString.replace(/\B(?=(\d{3})+(?!\d))/g, "."); } });