// ----- Google Reader ------ // @url http://www.google.com/reader/view/ // @include http://*.google.*/reader/view/* // @name Google Reader // @desc Notifies about count of new RSS feeds. // version 0.0 //standard calls //standard functions function show(){ SSB.ensureVisible() } function showMessage(title, msg){ var html = '' + ''+ '
'+ ''+ 'Google Reader '+ title + ''+ ''+ 'X'+ ''+ '
'+ '
'+ msg+ '
'+ '' + ''; SSB.notify(html, 140, 70, 5); //SSB.simpleNotify(msg,'javascript:show()'); } var refreshInterval = 60; //tester var testMode=false; if (testMode){ SSB.console.init("debug"); SSB.console.debug("test: running in test mode"); refreshInterval = 30; window.setInterval('test()',20*1000); //SSB.setIcon( 'rss2.com/favicon.ico'); } function test(){ SSB.console.debug("test: resetting value"); //SSB.prefs.setValue('num_unread', '-1'); } //schedulers window.setInterval('bblsCheckLinkChange()',refreshInterval*1000); function bblsCheckLinkChange() { SSB.console.debug("in bblsCheckLinkChange()"); /* make sure we've got a title we can work with */ if (document.title.search('Google Reader') == -1) { SSB.console.error("didnt get title"); return; } /* get current number of unread items */ var curUnread = bblsGetCurUnread(); if (curUnread == -1) { SSB.console.error("didnt get current underad items"); return; } /* get previous number of unread items */ var prevUnread = SSB.prefs.getValue('num_unread'); SSB.console.error("prevUnread ="+prevUnread); /* immediately update with new value */ SSB.prefs.setValue('num_unread', curUnread+''); if (prevUnread == null || prevUnread == '') { SSB.console.debug("setting prevUnread to 0"); prevUnread = 0; } else { prevUnread = parseInt(prevUnread); SSB.console.debug("got prevUnread as int "+prevUnread); } /* if the number grew (from n to n+), tell the user.*/ if (curUnread > prevUnread ){// && curUnread > 20) { var msg = curUnread + ' unread item' + (curUnread>1?'s':''); SSB.console.debug("displaying notification "+msg); showMessage("", msg); } /* update icon (icons are caches so we can give direct url) */ if(curUnread != 0){ SSB.console.debug("displaying rss2 icon"); SSB.setIcon( 'rss2.com/favicon.ico'); } else { SSB.console.debug("displaying reader icon"); SSB.setIcon( 'www.google.com/reader/ui/favicon.ico'); } } function bblsGetCurUnread() { SSB.console.debug(" in bblsGetCurUnread"); var title = document.title; SSB.console.debug(" got title as "+title); if (title.length > 13) { var unread = title.match(/(Google Reader.*\()(\d+)(\))/) SSB.console.debug("got unread as "+unread[2]); return parseInt(unread[2]) } SSB.console.debug("got 0 unread items"); return 0; }