All pastes #175051 Raw Edit

saidul_aa

public text v1 · immutable
·published 2006-09-18 13:28 UTC
rendered paste body
var extTrackconnection='no';
var extensiontracker = {
  extName:"Not Loaded",
  extDwnWeek:"X",
  extDwnTotal:"X",
  onLoad: function() {
    // initialization code
    this.initialized = true;
    var label = this.extName + " : " + this.extDwnWeek + " / " + this.extDwnTotal;
    document.getElementById('ExtTrackLbl').value = label;
    this.getData(3067);
    window.open("chrome://extensiontracker/content/devDisp.xul","findfile","chrome");
  },
  setVar: function(){
    var label = this.extName + " : " + this.extDwnWeek + " / " + this.extDwnTotal;
    document.getElementById('ExtTrackLbl').value=label;
  },
  getData: function(extensionID){
     extTrackconnection='no';
     req = new XMLHttpRequest();
     setTimeout('if(extTrackconnection=="no"){document.getElementById("ExtTrackLbl").value = "ERR Connection";req.abort();this.setVar();}',15*1000);
     req.open('GET', 'https://addons.mozilla.org/firefox/' + extensionID + '/', true);
     req.onreadystatechange = function () {
       if (req.readyState == 4) {
          if(req.status == 200){
           extTrackconnection='yes';
           var pagehtml=req.responseText;
           //remove till colon to enable testvar :var pagehtml='<li>Total Downloads: 518 &nbsp;&#8212;&nbsp; Downloads this Week: 521</li><h2><strong>WOW Status</strong> &raquo; Overview</h2>';
           var totalExp = /Total Downloads: \d* &nbsp;&#8212;&nbsp; /i;
           var total = totalExp.exec(pagehtml);
           total=total[0];
           total=total.substring(17,total.length-21);
           extensiontracker.extDwnTotal=total;
           var weekExp = /Downloads this Week: \d*</i;
           var week = weekExp.exec(pagehtml);
           week=week[0];
           week=week.substring(21,week.length-1);
           extensiontracker.extDwnWeek=week;
           var nameExp = /<h2><strong>[^/r]*</i
           var name = nameExp.exec(pagehtml);
           name=name[0];
           name=name.substring(12,name.length-1);
           extensiontracker.extName=name;
           extensiontracker.setVar();
          }else{
           document.getElementById('ExtTrackLbl').value = "ERR Connection";
           req.abort();
          }
       }
     };
     req.send(null);
  },
  testMe: function(){
     alert('it works');
  }
};
window.addEventListener("load", function(e) { extensiontracker.onLoad(e); }, false);