Last active
January 4, 2016 19:59
-
-
Save Soft/8670840 to your computer and use it in GitHub Desktop.
Notifications for Feedbin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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