Have you ever wondered how the GMail login screen displays the running count of Gmail mailbox size? Like this:
Don’t throw anything away.
Over 5000 megabytes (and counting) of free storage so you’ll never need to delete another message.
The above GMail size display is dynamic using JavaScript. It will be the same as it displays in GMail homepage.
At last today I went through the HTML source code of the page to figure this out. Now I know that GMail size has been increasing 100 MB per month (at least as per their JavaScript!)
Let me go down a bit deep into the technology (JavaScript) details. Sorry, if it bores you!
There is a JavaScript array in the page:
var CP = [ [ 1193122800000, 4321 ],
[ 1199433600000, 6283 ],
[ 2147328000000, 43008 ]];
The first array element is JavaScript time and second element is the storage size in MB expected at that specific time.
1117609200000 means June 01, 2005 and the storage expected was 2250 MB, on July 01, 2005 it was 2350 MB and on August 01, 2005 it is 2450 MB. That is 100 MB per month.
To display the running count, Google uses JavaScript to prorate the storage at the current system time.
I copied the HTML source of this page into a text file and saved as HTML in to my local disk. I wrote the following piece of script just below the CP array declaration.
for (var myDate = new Date(), c = 0; c < CP.length; c++) {
myDate.setTime(CP[0]);
document.write(“Local time: ” + myDate.toLocaleString() + “<br />”);
document.write(“GMail Size: ” + CP[1] + ” MB<br /><hr />”);
}
Now when you open the HTML in browser, the script prints the output like this:
Local time: Wednesday, June 01, 2005 12:00:00 AM
GMail Size: 2250 MB
Local time: Friday, July 01, 2005 12:00:00 AM
GMail Size: 2350 MB
Local time: Monday, August 01, 2005 12:00:00 AM
GMail Size: 2450 MB
The time here is Pacific Time (Google’s local time)
Here is the code I used for displaying on this blog.
<script type=”text/javascript”><!–
//Script to display running GMAIL inbox size
function updateEmailSize() {
var CP = [ [ 1193122800000, 4321 ], [ 1199433600000, 6283 ], [ 2147328000000, 43008 ]];
var now = (new Date()).getTime();
var quota, i;
if (document.getElementById) {
quota = document.getElementById(“quota”);
} else if (window[“quota”]) {
quota = window[id];
}
for (i = 0; i < CP.length; i++) {
if (now < CP[i][0]) {
break;
}
}
if (i == CP.length) {
quota.innerHTML = ‘Over ‘ + CP[i – 1][1];
} else {
var ts = CP[i – 1][0];
var bs = CP[i – 1][1];
quota.innerHTML = Math.floor(((now-ts) / (CP[i][0]-ts) * (CP[i][1]-bs)) + bs);
}
}
updateEmailSize();
// –></script>
Be the first to comment