// Initiate a new preference instance. var gPref = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); // Elements of the windows var userName; var timer; // Create a variable for the timer process. var gTimerID; // Create a variable for HTTP requests. var gXMLHttpRequest; function caggInit() { // Initial update of notifier icon. window.setTimeout(updateGet,1000); } function processClick(event) { // Right-click event if (event.button == 2) { var windowFeatures = "chrome,modal=yes,resizable=no"; window.openDialog('chrome://comic-aggregator-notifier/content/preferences.xul','PrefWindow',windowFeatures,'browser'); return; } // Left-click event (also single click, like Mac) if (event.button == 0) { updateGet(); } } function updateGet() { // Cancel previously submitted notifier job. window.clearTimeout(gTimerID); // Load the notifier poll timer. try { timer = gPref.getIntPref('cagg.time'); } catch(e) { timer = 180; } // Re-submit with the appropriate poll timer. gTimerID = window.setTimeout(updateGet,timer * 1000); // Load the notifier email address. try { userName = gPref.getCharPref('cagg.user'); } catch(e) { return; } gXMLHttpRequest = new XMLHttpRequest(); gXMLHttpRequest.onload = updateSet; gXMLHttpRequest.open('GET','http://comics.proyectoanonimo.com/ws/' + userName + '/unread'); gXMLHttpRequest.setRequestHeader('User-Agent','ComicAggregatorNotifier/Comic Aggregator Notifier for Mozilla/1.0'); gXMLHttpRequest.send(null); } function updateSet() { var icon = document.getElementById('cagg.icon'); var unreadComic = getElementsByTagNames("unread_comic",gXMLHttpRequest.responseText); var count = unreadComic[0].getAttribute("count"); switch(count) { case '0': icon.setAttribute("src","chrome://comic-aggregator-notifier/content/off.png"); break; default: icon.setAttribute("src","chrome://comic-aggregator-notifier/content/on.png"); break; } var number = document.getElementById('cagg.number'); number.setAttribute("value",count); } function getElementsByTagNames(list,obj) { if (!obj) var obj = document; var tagNames = list.split(','); var resultArray = new Array(); for (var i=0;i