diff --git a/src/content/notion.js b/src/content/notion.js index 2a2da8f33..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() : ''; @@ -26,7 +27,8 @@ togglbutton.render( const link = togglbutton.createTimerLink({ className: 'notion', - description: getDescription + description: getDescription, + autoTrackable: true, }); const wrapper = createWrapper(link); @@ -35,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 : ''; + 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') + } } - } 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 @@ -93,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() : ''; 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