background.js
// goes through each feed and gets how many you haven't read since last time you were there
goes through each feed and gets how many you haven't read since last time you were there
goes through each feed and gets how many you haven ' t read since last time you were there
function CheckForUnread()
{
    var req = new XMLHttpRequest();
    var toID = setTimeout(req.abort, 60000);
    var feedID = feeds[checkForUnreadCounter].id;
    var now = new Date();
    feedInfo[feedID] = {title: "", description: "", loading: true, items: [], error: ""};
    if(viewerPort != null)
    {
        viewerPort.postMessage({type: "feedupdatestarted", id: feedID});
    }
    try
    {
        req.open("get", feeds[checkForUnreadCounter].url.replace(/feed:\/\//i, "http://"), true);
        req.overrideMimeType('text/xml');
        req.onreadystatechange = function()
        {
            if(req.readyState == 4)
            {
                clearTimeout(toID);
                var doc = req.responseXML;
                if(unreadInfo[feedID] == null)
                {
                    unreadInfo[feedID] = {unreadtotal: 0, readitems: {}};
                }
                unreadInfo[feedID].unreadtotal = 0;
                if(req.status == 200)
                {
                    if(doc)
                    {
                        var readItemCount = 0;
                        var item = null;
                        var entryID = null;
                        var entryIDs = {};
                        var entries =  GetElementsByTagName(doc, [], "entry", "item");
                        var rootNode = GetElementByTagName(doc, null, "feed", "rss", "rdf:RDF");
                        var author = null;
                        var name = null;
                        if(rootNode != null)
                        {
                            if(rootNode.nodeName == "feed")
                            {
                                feedInfo[feedID].title = GetNodeTextValue(GetElementByTagName(rootNode, null, "title"));
                                feedInfo[feedID].description = GetNodeTextValue(GetElementByTagName(rootNode, null, "subTitle", "description"));
                            }
                            else
                            {
                                var channel = GetElementByTagName(rootNode, null, "channel");
                                if(channel != null)
                                {
                                    feedInfo[feedID].title = GetNodeTextValue(GetElementByTagName(channel, null, "title"));
                                    feedInfo[feedID].description = GetNodeTextValue(GetElementByTagName(channel, null, "description", "subTitle"));
                                }
                            }
                        }
                        for(var e=0;e < entries.length;e++)
                        {
                            item = {};
                            item.title = GetNodeTextValue(GetElementByTagName(entries[e], null, "title"), "No Title");
                            item.date = GetNodeTextValue(GetElementByTagName(entries[e], null, "pubDate", "updated", "dc:date", "date", "published")); 
                            item.content = "";
                            if(e <= feeds[checkForUnreadCounter].maxitems)
                            {
                                item.url = GetFeedLink(entries[e]);
                                if(options.showfeedcontent)
                                {
                                    item.content = GetNodeTextValue(GetElementByTagName(entries[e], null, "content:encoded", "content")); 
                                }
                                if(item.content == "")
                                {
                                    item.content = GetNodeTextValue(GetElementByTagName(entries[e], null, "description", "summary"));
                                }
                                author = GetElementByTagName(entries[e], null, "author", "dc:creator");
                                if(author != null)
                                {
                                    name = GetElementByTagName(author, null, "name");
                                    if(name != null)
                                    {
                                        item.author = GetNodeTextValue(name);
                                    }
                                    else
                                    {
                                        item.author = GetNodeTextValue(author);
                                    }
                                }
                                else
                                {   
                                    item.author = "&nbsp;";
                                }
                            }
                            feedInfo[feedID].items.push(item);
                            entryIDs[MD5(item.title + item.date)] = 1;
                        }
                        for(var key in unreadInfo[feedID].readitems)
                        {
                            if(entryIDs[key] == null)
                            {
                                if(now > new Date(unreadInfo[feedID].readitems[key]))
                                {
                                    delete unreadInfo[feedID].readitems[key];
                                }
                            }
                            else
                            {
                                readItemCount++;
                            }
                        }
                        unreadInfo[feedID].unreadtotal = entries.length - readItemCount;
                       }
                       else
                       {
                         feedInfo[feedID].error = "The response didn't have a valid responseXML property.";
                       }
                }
                else
                {
                    if(feedID != readLaterFeedID)
                    {
                        feedInfo[feedID].error = "Status wasn't 200.  It was " + req.status + " and frankly I don't know how to handle that.  If it helps, the status text was '" + req.statusText + "'.";
                    }
                    else
                    {
                        feedInfo[feedID] = GetReadLaterItems();
                        unreadInfo[feedID].unreadtotal = feedInfo[feedID].items.length;
                    }
                }
                localStorage["unreadinfo"] = JSON.stringify(unreadInfo);
                if(viewerPort != null)
                {
                    viewerPort.postMessage({type: "feedupdatecomplete", id: feedID});
                }
                checkForUnreadCounter++;
                req = null;
                doc = null;
                feedInfo[feedID].loading = false;
                if(checkForUnreadCounter >= feeds.length || refreshFeed)
                {
                    CheckForUnreadComplete();
                }
                else
                {
                    CheckForUnread();
                }
            }
        }
        req.send(null);
    }
    catch(err)
    {
    }
}
function CheckForUnread ( ) { var req = new XMLHttpRequest ( ) ; var toID = setTimeout ( req . abort , 60000 ) ; var feedID = feeds [ checkForUnreadCounter ] . id ; var now = new Date ( ) ; feedInfo [ feedID ] = { title : "" , description : "" , loading : true , items : [ ] , error : "" } ; if ( viewerPort != null ) { viewerPort . postMessage ( { type : "feedupdatestarted" , id : feedID } ) ; } try { req . open ( "get" , feeds [ checkForUnreadCounter ] . url . replace ( / feed:\/\/ / i , "http://" ) , true ) ; req . overrideMimeType ( 'text/xml' ) ; req . onreadystatechange = function ( ) { if ( req . readyState == 4 ) { clearTimeout ( toID ) ; var doc = req . responseXML ; if ( unreadInfo [ feedID ] == null ) { unreadInfo [ feedID ] = { unreadtotal : 0 , readitems : { } } ; } unreadInfo [ feedID ] . unreadtotal = 0 ; if ( req . status == 200 ) { if ( doc ) { var readItemCount = 0 ; var item = null ; var entryID = null ; var entryIDs = { } ; var entries = GetElementsByTagName ( doc , [ ] , "entry" , "item" ) ; var rootNode = GetElementByTagName ( doc , null , "feed" , "rss" , "rdf:RDF" ) ; var author = null ; var name = null ; if ( rootNode != null ) { if ( rootNode . nodeName == "feed" ) { feedInfo [ feedID ] . title = GetNodeTextValue ( GetElementByTagName ( rootNode , null , "title" ) ) ; feedInfo [ feedID ] . description = GetNodeTextValue ( GetElementByTagName ( rootNode , null , "subTitle" , "description" ) ) ; } else { var channel = GetElementByTagName ( rootNode , null , "channel" ) ; if ( channel != null ) { feedInfo [ feedID ] . title = GetNodeTextValue ( GetElementByTagName ( channel , null , "title" ) ) ; feedInfo [ feedID ] . description = GetNodeTextValue ( GetElementByTagName ( channel , null , "description" , "subTitle" ) ) ; } } } for ( var e = 0 ; e < entries . length ; e ++ ) { item = { } ; item . title = GetNodeTextValue ( GetElementByTagName ( entries [ e ] , null , "title" ) , "No Title" ) ; item . date = GetNodeTextValue ( GetElementByTagName ( entries [ e ] , null , "pubDate" , "updated" , "dc:date" , "date" , "published" ) ) ; item . content = "" ; if ( e <= feeds [ checkForUnreadCounter ] . maxitems ) { item . url = GetFeedLink ( entries [ e ] ) ; if ( options . showfeedcontent ) { item . content = GetNodeTextValue ( GetElementByTagName ( entries [ e ] , null , "content:encoded" , "content" ) ) ; } if ( item . content == "" ) { item . content = GetNodeTextValue ( GetElementByTagName ( entries [ e ] , null , "description" , "summary" ) ) ; } author = GetElementByTagName ( entries [ e ] , null , "author" , "dc:creator" ) ; if ( author != null ) { name = GetElementByTagName ( author , null , "name" ) ; if ( name != null ) { item . author = GetNodeTextValue ( name ) ; } else { item . author = GetNodeTextValue ( author ) ; } } else { item . author = "&nbsp;" ; } } feedInfo [ feedID ] . items . push ( item ) ; entryIDs [ MD5 ( item . title + item . date ) ] = 1 ; } for ( var key in unreadInfo [ feedID ] . readitems ) { if ( entryIDs [ key ] == null ) { if ( now > new Date ( unreadInfo [ feedID ] . readitems [ key ] ) ) { delete unreadInfo [ feedID ] . readitems [ key ] ; } } else { readItemCount ++ ; } } unreadInfo [ feedID ] . unreadtotal = entries . length - readItemCount ; } else { feedInfo [ feedID ] . error = "The response didn't have a valid responseXML property." ; } } else { if ( feedID != readLaterFeedID ) { feedInfo [ feedID ] . error = "Status wasn't 200.  It was " + req . status + " and frankly I don't know how to handle that.  If it helps, the status text was '" + req . statusText + "'." ; } else { feedInfo [ feedID ] = GetReadLaterItems ( ) ; unreadInfo [ feedID ] . unreadtotal = feedInfo [ feedID ] . items . length ; } } localStorage [ "unreadinfo" ] = JSON . stringify ( unreadInfo ) ; if ( viewerPort != null ) { viewerPort . postMessage ( { type : "feedupdatecomplete" , id : feedID } ) ; } checkForUnreadCounter ++ ; req = null ; doc = null ; feedInfo [ feedID ] . loading = false ; if ( checkForUnreadCounter >= feeds . length || refreshFeed ) { CheckForUnreadComplete ( ) ; } else { CheckForUnread ( ) ; } } } req . send ( null ) ; } catch ( err ) { } }
goes through each feed and gets how many you haven't read since last time you were there
goes through each feed and gets how many you haven ' t read since last time you were there
// get data and be nice to mac rss feeds // initialize unread object if not setup yet // not sure if date is even needed anymore // don't bother storing extra stuff past max.. only title for Mark All Read // only guessing on just "content" // for some reason the author gets funky with floats if it's empty..  so whatever // count read that are in current feed // if the read item isn't in the current feed and it's past it's expiration date, nuke it // cheat the system, fill in read later info // onreadystate should already be called, so don't do anything!