From fb2b812dfa70f2f89f38b33c30c439ca1f5a30aa Mon Sep 17 00:00:00 2001 From: Shrey Gupta Date: Wed, 22 May 2024 07:31:00 +0300 Subject: [PATCH 1/4] feat(auto-tracker): Add auto tracking capability to extension --- src/content/github.js | 3 +++ src/content/notion.js | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/content/github.js b/src/content/github.js index 377d21fb5..ea4a48ad6 100644 --- a/src/content/github.js +++ b/src/content/github.js @@ -53,6 +53,7 @@ togglbutton.render( className: "github", description: description, projectName: projectElem && projectElem.textContent, + autoTrackerKey: "pull-issue" }); div.appendChild(link); @@ -83,6 +84,7 @@ togglbutton.render( className: "github", description: description, projectName: projectElem ? projectElem.textContent.trim() : "", + autoTrackerKey: "peek" }); div.appendChild(link); @@ -118,6 +120,7 @@ togglbutton.render( className: "github", description: getDescription, projectName: projectElem && projectElem.textContent, + autoTrackable: true }); const wrapper = createTag( diff --git a/src/content/notion.js b/src/content/notion.js index 2a2da8f33..f1a5b8b47 100644 --- a/src/content/notion.js +++ b/src/content/notion.js @@ -26,7 +26,8 @@ togglbutton.render( const link = togglbutton.createTimerLink({ className: 'notion', - description: getDescription + description: getDescription, + autoTrackerKey: "side_peek" }); const wrapper = createWrapper(link); @@ -75,7 +76,8 @@ togglbutton.render( const link = togglbutton.createTimerLink({ className: 'notion', - description: getDescription + description: getDescription, + autoTrackerKey: "document" }); const wrapper = createWrapper(link); From 4103ac86b2a500b836a305b193b8bdfb01925644 Mon Sep 17 00:00:00 2001 From: Shrey Gupta Date: Wed, 25 Sep 2024 14:27:04 +0530 Subject: [PATCH 2/4] feat(auto-tracker): Update config --- src/content/github.js | 3 --- src/content/onlyoffice.js | 6 ++++-- src/content/trello.js | 1 + 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/content/github.js b/src/content/github.js index ea4a48ad6..377d21fb5 100644 --- a/src/content/github.js +++ b/src/content/github.js @@ -53,7 +53,6 @@ togglbutton.render( className: "github", description: description, projectName: projectElem && projectElem.textContent, - autoTrackerKey: "pull-issue" }); div.appendChild(link); @@ -84,7 +83,6 @@ togglbutton.render( className: "github", description: description, projectName: projectElem ? projectElem.textContent.trim() : "", - autoTrackerKey: "peek" }); div.appendChild(link); @@ -120,7 +118,6 @@ togglbutton.render( className: "github", description: getDescription, projectName: projectElem && projectElem.textContent, - autoTrackable: true }); const wrapper = createTag( diff --git a/src/content/onlyoffice.js b/src/content/onlyoffice.js index 56c0e8082..817c30773 100644 --- a/src/content/onlyoffice.js +++ b/src/content/onlyoffice.js @@ -14,7 +14,8 @@ togglbutton.render( className: 'onlyoffice', description: description, projectName: project, - buttonType: 'minimal' + buttonType: 'minimal', + autoTrackable: true }); $('.project-title').appendChild(link); } @@ -62,7 +63,8 @@ togglbutton.render( className: 'onlyoffice', description: description, projectName: project, - buttonType: 'minimal' + buttonType: 'minimal', + autoTrackable: true }); elem.insertBefore(link, $('.check', elem)); const button = $('.toggl-button.onlyoffice', elem); diff --git a/src/content/trello.js b/src/content/trello.js index d7df5b815..9d4058fcd 100644 --- a/src/content/trello.js +++ b/src/content/trello.js @@ -39,6 +39,7 @@ togglbutton.render( description: getDescription, projectName: getProject, container: '[data-testid="card-back-name"]', + autoTrackable: true, }) // Pass through click on Trello button to the timer link From 997e6a6c3431b5fb813a0fb827af2665e97209a9 Mon Sep 17 00:00:00 2001 From: Shrey Gupta Date: Thu, 26 Sep 2024 17:16:19 +0530 Subject: [PATCH 3/4] feat(notion): Update auto track config --- src/content/notion.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/content/notion.js b/src/content/notion.js index f1a5b8b47..ca3baf458 100644 --- a/src/content/notion.js +++ b/src/content/notion.js @@ -27,7 +27,7 @@ togglbutton.render( const link = togglbutton.createTimerLink({ className: 'notion', description: getDescription, - autoTrackerKey: "side_peek" + autoTrackable: true, }); const wrapper = createWrapper(link); @@ -77,7 +77,6 @@ togglbutton.render( const link = togglbutton.createTimerLink({ className: 'notion', description: getDescription, - autoTrackerKey: "document" }); const wrapper = createWrapper(link); From 7055387b2120dd532b985197795111fd18782608 Mon Sep 17 00:00:00 2001 From: Shrey Gupta Date: Mon, 30 Sep 2024 16:29:54 +0530 Subject: [PATCH 4/4] fix(notion): Fix button not re-rendering on page change --- src/content/notion.js | 79 ++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/src/content/notion.js b/src/content/notion.js index ca3baf458..2ee4625ce 100644 --- a/src/content/notion.js +++ b/src/content/notion.js @@ -19,6 +19,7 @@ togglbutton.render( '.notion-peek-renderer:not(.toggl)', { observe: true }, function (elem) { + if (!elem) return; function getDescription () { const descriptionElem = elem.querySelector('.notion-peek-renderer .notion-scroller h1[contenteditable]'); return descriptionElem ? descriptionElem.textContent.trim() : ''; @@ -36,54 +37,63 @@ togglbutton.render( if (root) { root.parentElement.prepend(wrapper); } else { - elem.querySelector('div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(3)').prepend(wrapper) + const selector = elem.querySelector('div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(3)') + if (!selector) return; + selector.prepend(wrapper) } } ); -togglbutton.render( - '.notion-topbar-action-buttons:not(.toggl)', - { observe: true }, - function (elem) { - if (!elem) return; +setTimeout(() => { + togglbutton.render( + '.notion-topbar-action-buttons', + { observe: true, debounceInterval: 1000 }, + function (elem) { + if (!elem) return; + const elements = document.querySelectorAll('.notion-topbar-action-buttons .toggl-button-notion-wrapper') + if(elements.length > 0) { + elements.forEach(element => element.remove()) + } - elem.style.position = 'relative'; + elem.style.position = 'relative'; - function getDescription () { - const controls = document.querySelector('.notion-page-controls'); - const topBar = document.querySelector('.notion-topbar'); - let title = ''; + function getDescription () { + const controls = document.querySelector('.notion-page-controls'); + const topBar = document.querySelector('.notion-topbar'); + let title = ''; - if (controls) { - if (controls.nextElementSibling) { - title = controls.nextElementSibling; - } else { - const parent = controls.parentElement; + if (controls) { + if (controls.nextElementSibling) { + title = controls.nextElementSibling; + } else { + const parent = controls.parentElement; - if (!parent) return ''; + if (!parent) return ''; - title = parent ? parent.nextElementSibling : ''; - } - } else if (topBar) { - const breadcrumbs = topBar.querySelector('div > .notranslate') - if (breadcrumbs) { - title = breadcrumbs.childNodes[breadcrumbs.childNodes.length - 1].querySelector('.notranslate:last-child') + title = parent ? parent.nextElementSibling : ''; + } + } else if (topBar) { + const breadcrumbs = topBar.querySelector('div > .notranslate') + if (breadcrumbs) { + title = breadcrumbs.childNodes[breadcrumbs.childNodes.length - 1].querySelector('.notranslate:last-child') + } } - } - return title ? title.textContent.trim() : ''; - } + return title ? title.textContent.trim() : ''; + } - const link = togglbutton.createTimerLink({ - className: 'notion', - description: getDescription, - }); + const link = togglbutton.createTimerLink({ + className: 'notion', + description: getDescription, + }); - const wrapper = createWrapper(link); + const wrapper = createWrapper(link); - elem.prepend(wrapper); - } -); + elem.prepend(wrapper); + }, + '.notion-topbar .shadow-cursor-breadcrumb *,title' + ); +}, 2000) /** * @name Notion Calendar @@ -94,6 +104,7 @@ togglbutton.render( 'div[data-context-panel-root]:not(.toggl)', { observe: true }, function (elem) { + if (!elem) return; function getDescription () { const descriptionElem = elem.querySelector('div[contenteditable="true"]'); return descriptionElem ? descriptionElem.textContent.trim() : '';