Last active
March 1, 2016 16:57
-
-
Save ctsstc/aab31c79b0fd96ef4fc0 to your computer and use it in GitHub Desktop.
This file contains 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
var YTThumbQuality = { | |
_default: "default", | |
mqdefault: "mqdefault", | |
sddefault: "sddefault", | |
hqdefault: "hqdefault" | |
} | |
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 ? "https://musiqpad.com/pads/lib/img/icon.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.showQpNotification({next:{song:{title: "This is a test title", cid: "OmP9tWixLoI"}}}); | |
}, | |
atMe: function(dataError, data, dataParent) { | |
var me = API.room.getUser(); | |
var myId = me.uid; | |
var username = me.un; | |
if (data.uid != myId && data.message.indexOf(username) > -1) | |
{ | |
var them = API.room.getUser(data.uid); | |
qpNotification.showNotification("Mention From: "+them.un, data.message); | |
} | |
} | |
} | |
qpNotification.getPermission(); | |
API.on(API.DATA.EVENTS.ADVANCE, qpNotification.showQpNotification); | |
API.on(API.DATA.EVENTS.CHAT, qpNotification.atMe); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment