Skip to content

Instantly share code, notes, and snippets.

@dpschen
Forked from JoelSutherland/lazy-zendesk.js
Created January 9, 2024 17:43
Show Gist options
  • Save dpschen/58756a804eb2505f6d92426b6dec8b76 to your computer and use it in GitHub Desktop.
Save dpschen/58756a804eb2505f6d92426b6dec8b76 to your computer and use it in GitHub Desktop.
(function () {
function loadZendeskChat(callback) {
var zdscript = document.createElement('script');
zdscript.setAttribute('id','ze-snippet');
zdscript.src = 'https://static.zdassets.com/ekr/snippet.js?key=XXX-XXX-XXX-XXX';
(document.getElementsByTagName('body')[0]).appendChild(zdscript);
window.zdonload = setInterval(function(){
if(typeof zE !== "undefined" && typeof zE.activate !== "undefined") {
clearInterval(window.zdonload);
callback();
}
},50,null)
};
window.loadAndOpenZendeskChat = function() {
var button = document.getElementById('zdbutton');
localStorage.setItem('ff_zd_hasOpened',true);
button.innerHTML = 'Loading...';
loadZendeskChat(function(){
window.setTimeout(function(){
zE.activate();
button.parentNode.removeChild(button);
},1000);
});
}
if(localStorage.getItem('ff_zd_hasOpened')) {
loadZendeskChat(function(){});
} else {
document.getElementsByTagName('body')[0].insertAdjacentHTML('beforeend','<button id="zdbutton" aria-label="Launch Help Chat Window" onClick="window.loadAndOpenZendeskChat();">Help</button>');
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment