-
-
Save cha0s/9337344dc0257924808d to your computer and use it in GitHub Desktop.
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
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