I am new to javascript but wanted to write a Safari extension to display the badge count of the unread emails in a gmail account. When the user clicks the button it goes to gmail. I got it working and its quite handy. The only thing I can't figure out is how (when the user is not logged into gmail) to suppress my XMLHttpRequest from causing safari to put up a login prompt that doesn't even work.
Here is my request.
// url for Gmail atom feed
var url = "http://mail.google.com/mail/feed/atom";
// request url
xmlHttp = new XMLHttpRequest();
xmlHttp.open('GET', url, true);
xmlHttp.onreadystatechange = checkForNewMessagesCallBack;
xmlHttp.send(null);
And here is my handler.
if (xmlHttp.readyState==4 && xmlHttp.status == 200) // 4 = finished and 200 = success
{
// finished loading
// extract the XML retrieved from the server
xmlResponse = xmlHttp.responseXML;
// get xml document
var xmlDoc = xmlResponse.documentElement;
// get <fullcount> value
var unreadCount = xmlDoc.getElementsByTagName("fullcount")[0].childNodes[0].nodeValue
//alert("unread = " + unreadCount);
// unreadCount is the number of unread email, set badge to this value
updateUnreadMessageCount(unreadCount);
}