From 2a7739439db56a7a1b1610bddeeecd75447e93e0 Mon Sep 17 00:00:00 2001 From: Alisson Oliveira Souza Date: Wed, 26 Apr 2023 11:51:53 -0300 Subject: [PATCH] fix(zendesk): Render button in the new UI Closes #2183 --- src/content/zendesk.js | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/content/zendesk.js b/src/content/zendesk.js index 8ebd59823..a2fe20963 100644 --- a/src/content/zendesk.js +++ b/src/content/zendesk.js @@ -38,6 +38,49 @@ setTimeout(() => { ); }, 1000); + +// Zendesk new UI Apr 2023 +setTimeout(() => { + togglbutton.render( + '[data-garden-id="pane"]:not(.toggl)', + { observe: true }, + function (elem) { + if (elem.id === ':r1:--primary-pane') return + let description; + const projectName = $('title').textContent; + + const titleFunc = function () { + const titleElem = $('[data-test-id="omni-header-subject"]', elem); + const ticketNum = location.href.match(/tickets\/(\d+)/); + + if (titleElem !== null) { + description = titleElem.value.trim(); + } + + if (ticketNum) { + description = '#' + ticketNum[1].trim() + ' ' + description; + } + return description; + }; + + const link = togglbutton.createTimerLink({ + className: 'zendesk', + description: titleFunc, + projectName: projectName && projectName.split(' - ').shift() + }); + + // Check for strange duplicate buttons. Don't know why this happens in Zendesk. + if (document.querySelector('.toggl-button')) { + document.removeChild(elem.querySelector('.toggl-button')); + } + elem.querySelector('[data-side-conversations-anchor-id="1"]').firstChild + .firstChild + .firstChild + .appendChild(link); + } + ); +}, 1000); + // Zendesk pre-2021 setTimeout(() => { togglbutton.render(