javascript:(function() { var username = "milcom_"; var timeToDisplayNotifInSeconds = 5; var notificationRegistrar = function(){ var notify = function(message, callback) { var notification = new Notification(message); callback(notification); }; angular.element(document.body).injector().invoke(['$rootScope', 'shrub-socket', 'shrub-ui/notifications', function($rootScope, socket, notifications) { if (window.notifyMentions) { window.notifyMentions = false; notifications.add({text: 'Notifications for mentions disabled.'}); } else { window.notifyMentions = true; socket.on('reddichat.chat.message', function(message) { if(message.text.search(username) > -1) { notify(message. from + ": " + message.text, function(notification){ setTimeout(function(){ notification.close(); }, timeToDisplayNotifInSeconds * 1000); }); } }); notifications.add({text: 'Notifications for mentions enabled.'}); } $rootScope.$digest(); }]); }; var registerNotificationsIfPermitted = function(callback) { if(!("Notification" in window)) { alert("This browser does not support desktop notification"); } else if(Notification.permission == "granted") { callback(); } else { Notification.requestPermission(function(permission){ if(permission == "granted") { callback(); } }); } }; registerNotificationsIfPermitted(notificationRegistrar); })();