Last active
December 20, 2017 13:10
-
-
Save bidulock/4560721 to your computer and use it in GitHub Desktop.
A basic user script to enable html5 notifications on zendesk sites when there are incoming chat requests
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
// ==UserScript== | |
// @name Desktop Notifications for zendesk | |
// @include https://*.zendesk.com/agent/* | |
// ==/UserScript== | |
setTimeout(function () { | |
var initNotifications = window.webkitNotifications ? function () { | |
var notify = window.webkitNotifications; | |
var n = null; | |
function createNotification() { | |
n = notify.createNotification("", "Pending chat requests", "Someone wants to chat with us. HELP THEM!!!"); | |
n.onclose = createNotification; | |
} | |
var invites = document.getElementById("chat-invites"); | |
if (invites && notify.checkPermission() == 0) createNotification(); | |
var watching = false; | |
var watch = function () { | |
if (n && invites) { | |
invites.children.length > 0 ? n.show() : n.close(); | |
setTimeout(watch, 500); | |
} | |
}; | |
if (notify.checkPermission() == 0) { | |
watch(); | |
} else { | |
document.body.addEventListener("click", function () { | |
if (notify.checkPermission() == 0) { | |
if (!watching) { | |
watching = true; | |
initNotifications(); | |
} | |
} else { | |
notify.requestPermission(); | |
} | |
}, false); | |
} | |
} : function () {}; | |
initNotifications(); | |
}, 10000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment