Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Desktop notifications are only available on WebKit browsers, for now, so only carry out
- // notifications if the API is available.
- if (window.webkitNotifications) {
- // Just a piece of data to determine whether 1) the page just loaded, and 2) there are any
- // new elements in the feed.
- var lastTime = null;
- // This is to check if you have permissions to display notifications. Usually, the
- // checkPermissions method only returns a number. 0 being that you don't have permission
- // to display notifications, yet.
- if (window.webkitNotifications.checkPermissions() <= 0) {
- // If you don't have permission, then get the permission from the user.
- window.webkitNotifications.requestPermission(callback);
- }
- // The code below will run every thirty seconds.
- setInterval(function () {
- // What we want to do here is carry out an AJAX request to check for changes in the RSS
- // feed only if we have permission to display notifications. Otherwise, what's the point
- // of checking for changes if the user doesn't want to know?
- if (window.webkitNotifications.checkPermissions() > 0) {
- $.jFeed({
- url: 'http://masseyappnews.wordpress.com/feed',
- success: function (feed) {
- // Looks at the latest item's time, and checks to see if it's any different
- // than what we have in memory.
- if (lastTime !== feed.items[0].updated) {
- // If so, determine whether we recorded the time, or not.
- if (lastTime !== null) {
- // If we did record the time, that means there are new content from
- // the last time we checked.
- window.webkitNotifications()
- }
- // Update the last time.
- lastTime = feed.items[0].updated;
- }
- }
- });
- }
- }, 30000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement