Skip to content

Commit

Permalink
fix(notion): Fix button not re-rendering on page change
Browse files Browse the repository at this point in the history
  • Loading branch information
with-shrey committed Sep 30, 2024
1 parent 1f76bad commit 5fb6ca1
Showing 1 changed file with 45 additions and 34 deletions.
79 changes: 45 additions & 34 deletions src/content/notion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() : '';
Expand All @@ -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
Expand All @@ -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() : '';
Expand Down

0 comments on commit 5fb6ca1

Please sign in to comment.