Skip to content

Instantly share code, notes, and snippets.

@bidulock
Last active December 20, 2017 13:10
Show Gist options
  • Save bidulock/4560721 to your computer and use it in GitHub Desktop.
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
// ==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