Skip to content

Instantly share code, notes, and snippets.

@Benzi
Last active August 29, 2015 14:18
Show Gist options
  • Save Benzi/651312c7870a1254949c to your computer and use it in GitHub Desktop.
Save Benzi/651312c7870a1254949c to your computer and use it in GitHub Desktop.
Get chat notifications from plug.dj
(function() {
var notify = false;
if ("Notification" in window) {
if (Notification.permission === "granted") {
notify = true;
} else if (Notification.permission === "default") {
Notification.requestPermission(function(permission) {
if (!("permission" in Notification && permission === "granted")) {
Notification.permission = permission;
notify = true;
}
});
}
}
API.on(API.CHAT, function(data) {
if (notify) {
var notification = new Notification("Chat message:", {
body: data.un + " : " + data.message,
icon: "http://i.benzi.io/WGXI.png"
});
setTimeout(function() {
notification.close();
}, 10000);
}
});
API.chatLog("Chat notifications ON");
API.chatLog("Credit: http://benzi.io");
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment