Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auto-tracker): Add auto tracking capability to extension #2302

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 47 additions & 35 deletions src/content/notion.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ 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() : '';
}

const link = togglbutton.createTimerLink({
className: 'notion',
description: getDescription
description: getDescription,
autoTrackable: true,
});

const wrapper = createWrapper(link);
Expand All @@ -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(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the setTimeout here? Does the debounceInterval set to 2000 does not work?

Copy link
Contributor Author

@with-shrey with-shrey Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesnt do it for the first render

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
Expand All @@ -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() : '';
Expand Down
6 changes: 4 additions & 2 deletions src/content/onlyoffice.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ togglbutton.render(
className: 'onlyoffice',
description: description,
projectName: project,
buttonType: 'minimal'
buttonType: 'minimal',
autoTrackable: true
});
$('.project-title').appendChild(link);
}
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/content/trello.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading