gmail storage counter

Status
Not open for further replies.

Spades

New member
Mar 19, 2007
660
5
0
Florida
Been killing myself trying to find a script similar to the gmail storage counter on their login page. A bunch of people have broken it down and explained that it uses dates as reference and then calculates (prorates) the current storage based on that. I've tore it apart myself but not being very javascript savvy it hasn't made a whole lot of sense to me.

I'd like to have an increasing number without the decimal ... for example, 400,000 and increase it in increments of 500.

Anybody done this before??

Here's the gmail javascript for reference:

Code:
     <script type=text/javascript>
     <!--
     var CP = [
      [ 1136102400000, 2680 ],
      [ 1149145200000, 2730 ],
      [ 1167638400000, 2800 ]
     ];
     var quota;
     var PAD = '.000000'; 
     function el(id) {
       if (document.getElementById) {
         return document.getElementById(id);
       } else if (window[id]) {
         return window[id];
       }
       return null;
     }
     function OnLoad() {
       if (!quota) {
         quota = el("quota");
         updateQuota();
       }
     }
     function updateQuota() { 
       if (!quota) {
         return;
       }
       var now = (new Date()).getTime(); 
       var i;
       for (i = 0; i < CP.length; i++) {
         if (now < CP[i][0]) {
           break;
         }
       }
       if (i == 0) {
         setTimeout(updateQuota, 1000); 
       } else if (i == CP.length) {
         quota.innerHTML = CP[i - 1][1];
       } else {
         var ts = CP[i - 1][0];
         var bs = CP[i - 1][1];
         quota.innerHTML = format(((now-ts) / (CP[i][0]-ts) * (CP[i][1]-bs)) + bs); 
         setTimeout(updateQuota, 1000); 
       } 
     } 
     function format(num) { 
       var str = String(num); 
       var dot = str.indexOf('.'); 
       if (dot < 0) { 
          return str + PAD; 
       } if (PAD.length > (str.length - dot)) { 
         return str + PAD.substring(str.length - dot); 
       } else { 
         return str.substring(0, dot + PAD.length); 
       } 
     } 
     // -->
     </script>


 THIS WAS IN THE BODY
       <span id=quota>2000</span>
     <script>
     <!--
     quota = el("quota");
     updateQuota();
     // -->
     </script>
 


Status
Not open for further replies.