Skip to content

Instantly share code, notes, and snippets.

@Soft
Last active January 4, 2016 19:59
Show Gist options
  • Save Soft/8670840 to your computer and use it in GitHub Desktop.
Save Soft/8670840 to your computer and use it in GitHub Desktop.
Notifications for Feedbin
// ==UserScript==
// @name Feedbin unread notifications
// @match *://feedbin.me/*
// @grant none
// @author Samuel Laurén
// ==/UserScript==
var count = () => {
var unreadCount = document.querySelector("[data-behavior~=all_unread] .count");
return parseInt(unreadCount.innerHTML, 10);
};
var createNotifier = () => {
var lastCount = count();
return () => {
var items = count();
if (lastCount < items) {
displayNotification(items);
}
lastCount = items;
};
};
var displayNotification = items => {
console.log("Displaying notification for " + items + " items");
new Notification("Feedbin", {
body: items.toString() + " items available",
icon: document.querySelector("[rel=apple-touch-icon-precomposed]").href
});
};
var setupNotification = () => {
window.setInterval(createNotifier(), 30000);
};
if (Notification.permission === "granted") {
setupNotification();
} else if (Notification.persmission !== "denied") {
Notification.requestPermission((permission) => {
if (permission === "granted") {
setupNotification();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment