diff options
| author | 2014-08-08 21:30:23 +0200 | |
|---|---|---|
| committer | 2014-08-08 21:30:23 +0200 | |
| commit | d289c5340f3b21f1561e57390e89b0b5c7881d17 (patch) | |
| tree | 863d496c34dfaaf9514d913b2dd102677645db10 /p/scripts | |
| parent | a7632b54293100d71a6eadfcb98746da05358ddb (diff) | |
Add support of HTML5 notifications
Show a notification if there are at least 1 new article to read.
Support only window.Notification API.
See https://github.com/marienfressinaud/FreshRSS/issues/399
Diffstat (limited to 'p/scripts')
| -rw-r--r-- | p/scripts/main.js | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/p/scripts/main.js b/p/scripts/main.js index a82450e7f..bd412d6e9 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -768,6 +768,46 @@ function init_notifications() { } // </notification> +// <notifs html5> +var notifs_html5_permission = 'denied', + notifs_html5_shown = false; + +function notifs_html5_is_supported() { + return window.Notification !== undefined; +} + +function notifs_html5_ask_permission() { + window.Notification.requestPermission(function () { + notifs_html5_permission = window.Notification.permission; + }); +} + +function notifs_html5_show(nb) { + if (notifs_html5_permission !== "granted" || notifs_html5_shown) { + return + } + + var notification = new window.Notification(str_notif_title_articles, { + icon: "../themes/icons/favicon-256.png", + body: str_notif_body_articles.replace("\d", nb) + }); + + notification.onclick = function() { + window.location.reload(); + } + + notifs_html5_shown = true; +} + +function init_notifs_html5() { + if (!notifs_html5_is_supported()) { + return; + } + + notifs_html5_permission = notifs_html5_ask_permission(); +} +// </notifs html5> + function refreshUnreads() { $.getJSON('./?c=javascript&a=nbUnreadsPerFeed').done(function (data) { var isAll = $('.category.all > .active').length > 0; @@ -780,7 +820,12 @@ function refreshUnreads() { $('#new-article').show(); }; }); - faviconNbUnread(); + + var nb_unreads = str2int($('.category.all>a').attr('data-unread')); + if (nb_unreads > 0) { + faviconNbUnread(nb_unreads); + notifs_html5_show(nb_unreads); + } }); } @@ -1123,6 +1168,7 @@ function init_all() { init_shortcuts(); faviconNbUnread(); init_print_action(); + init_notifs_html5(); window.setInterval(refreshUnreads, 120000); } else { init_share_observers(); |
