From 031c0ece53409eedc996cd1bef6e3c84ab09b9da Mon Sep 17 00:00:00 2001 From: Shrey Gupta Date: Tue, 24 Sep 2024 14:29:50 +0530 Subject: [PATCH] feat(hubspot): Display button on all objects using generic selector (#2334) --- src/content/hubspot.js | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/content/hubspot.js b/src/content/hubspot.js index dbbb30f79..d2593708c 100644 --- a/src/content/hubspot.js +++ b/src/content/hubspot.js @@ -6,29 +6,33 @@ 'use strict'; togglbutton.render( - 'div[data-selenium-test="ticket-highlight-details"]:not(.toggl)', + 'div[data-selenium-test$="-highlight-details"]:not(.toggl)', { observe: true }, $container => { - function descriptionSelector () { - const $description = $('div[data-selenium-test="ticket-highlight-details"] h3'); - return $description.textContent.trim(); - } + try { + function descriptionSelector() { + const $description = $('div[data-selenium-test$="-highlight-details"] h3') ?? $('div[data-selenium-test$="highlightTitle"]'); + return $description.textContent.trim(); + } + + function tagsSelector() { + const pipeline = $('div#pipeline-select') ? $('div#pipeline-select').textContent.trim() : ''; + const stage = $('div#stage-select') ? $('div#stage-select').textContent.trim() : ''; - function tagsSelector () { - const pipeline = $('div#pipeline-select') ? $('div#pipeline-select').textContent.trim(): ''; - const stage = $('div#stage-select') ? $('div#stage-select').textContent.trim(): ''; + return [pipeline, stage]; + } - return [pipeline, stage]; + const link = togglbutton.createTimerLink({ + className: 'hubspot', + description: descriptionSelector, + tags: tagsSelector + }); + const rowContainer = document.createElement('div'); + rowContainer.setAttribute('class', 'flex-row align-center'); + rowContainer.appendChild(link); + $container.parentNode.appendChild(rowContainer); + } catch (e) { + console.error(e) } - const link = togglbutton.createTimerLink({ - className: 'hubspot', - project: 'Hubspot', - description: descriptionSelector, - tags: tagsSelector - }); - const rowContainer = document.createElement('div'); - rowContainer.setAttribute('class', 'flex-row align-center'); - rowContainer.appendChild(link); - $container.appendChild(rowContainer); } );