Skip to content

Instantly share code, notes, and snippets.

@mikepack
Created February 4, 2014 18:17
Show Gist options
  • Save mikepack/8809257 to your computer and use it in GitHub Desktop.
Save mikepack/8809257 to your computer and use it in GitHub Desktop.
The Old Reader Fluid badge and Growl notifications
setInterval(updateDockBadge, 5000);
setTimeout(notifyUnread, 5000);
var currentCount = '0';
function updateDockBadge() {
currentCount = jQuery('#unread_count .badge-info').text();
window.fluid.dockBadge = currentCount;
}
var oldCount = '0';
function notifyUnread() {
//return if !document.hidden;
if(oldCount != currentCount) {
// Grab the new articles and show a Growl
if(window.location.pathname != '/') {
window.location.pathname = '/';
}
var newArticles = parseInt(currentCount) - parseInt(oldCount);
if(newArticles > 0) {
var articles = jQuery('.dl-horizontal:first dd');
for(var i = 0 ; i < articles.length && i < newArticles ; i++) {
var article = $(articles.get(i)),
url = article.find('a').attr('href'),
source = article.prev('dt').text().trim(),
iconCss = $('ul.feeds-list a:contains("' + source + '") i').css('background-image'),
icon = /^url\((['"]?)(.*)\1\)$/.exec(iconCss)[2],
title = article.find('strong').text().trim(),
textNodes = article.find('p').contents().filter(function() { return this.nodeType === Node.TEXT_NODE }),
description = textNodes[textNodes.length - 1].data.trim();
window.fluid.showGrowlNotification({
title: title,
description: description,
priority: 1,
sticky: false,
identifier: title,
icon: icon,
onclick: function() {
window.fluid.activate();
window.location.pathname = url;
}
});
}
}
}
oldCount = currentCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment