Skip to content

Instantly share code, notes, and snippets.

@cha0s
Created February 12, 2015 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cha0s/cc46894e3f1704812f66 to your computer and use it in GitHub Desktop.
Save cha0s/cc46894e3f1704812f66 to your computer and use it in GitHub Desktop.
Reddichat notifications (thanks milcom!)
javascript:(function() { 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', 'shrub-user', function($rootScope, socket, notifications, user) { 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(user.instance().name) > -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); })();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment