Skip to content

Instantly share code, notes, and snippets.

@ctsstc
Created May 26, 2016 18:23
Show Gist options
  • Save ctsstc/69233ed473593516679f27cf24733045 to your computer and use it in GitHub Desktop.
Save ctsstc/69233ed473593516679f27cf24733045 to your computer and use it in GitHub Desktop.
var qpNotification = {
enabled: true,
notificationTimeout: 5000,
getPermission: function(callback) {
if (typeof Notification == 'undefined') {
return false;
}
Notification.requestPermission(function (permission) {
if (callback !== undefined)
{
callback(permission);
}
});
},
showNotification: function(title, message, iconPath) {
if (qpNotification.enabled)
{
iconPath = iconPath == undefined ? "/static/components/widgets/blog-feed/images/thumbnail.png" : iconPath;
qpNotification.getPermission(function(permission) {
if (permission !== 'granted') return;
var notification = new Notification(title, {
icon: iconPath,
body: message,
});
notification.onclick = function () {
window.focus();
this.close();
};
// hide after a given time
setTimeout(function() {
notification.close();
}, qpNotification.notificationTimeout);
});
}
},
showQpNotification: function(e) {
var song = e.next.song;
var title = song.title;
var ytid = song.cid;
var iconPath = "//i.ytimg.com/vi/"+ytid+"/"+YTThumbQuality._default+".jpg";
qpNotification.showNotification("musiqpad", title, iconPath);
},
test: function() {
qpNotification.showNotification("Wauw", "It works! C'est fantastic!");
},
}
qpNotification.getPermission(function() {
// on success
qpNotification.test();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment