mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-19 11:09:03 +00:00
Update panel.js
This commit is contained in:
parent
feaa55681f
commit
4cb0bf6b56
@ -9,73 +9,60 @@
|
|||||||
|
|
||||||
const { createElement } = require("../../pkg/helpers");
|
const { createElement } = require("../../pkg/helpers");
|
||||||
|
|
||||||
module.exports = (store) => {
|
module.exports = (store) => {
|
||||||
function initOutliner() {
|
// Observe for page changes
|
||||||
// Find headers when switching panels
|
const pageObserver = new MutationObserver((list, observer) => {
|
||||||
if (document.querySelector('.notion-page-content')) {
|
for ( let { addedNodes } of list) {
|
||||||
startContentObserver();
|
if (addedNodes[0]) {
|
||||||
};
|
if (addedNodes[0].className === 'notion-page-content') {
|
||||||
|
startContentObserver();
|
||||||
// Observe for page changes
|
|
||||||
const pageObserver = new MutationObserver((list, observer) => {
|
|
||||||
for ( let { addedNodes } of list) {
|
|
||||||
if (addedNodes[0]) {
|
|
||||||
if (addedNodes[0].className === 'notion-page-content') {
|
|
||||||
startContentObserver();
|
|
||||||
}
|
|
||||||
// Clear outline on database pages
|
|
||||||
else if (addedNodes[0].className === 'notion-scroller') {
|
|
||||||
contentObserver.disconnect();
|
|
||||||
const outline = document.querySelector('.outliner');
|
|
||||||
if (outline) outline.textContent = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
pageObserver.observe(document.body, {
|
|
||||||
childList: true,
|
|
||||||
subtree: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Observe for header changes
|
|
||||||
const contentObserver = new MutationObserver((list, observer) => {
|
|
||||||
list.forEach(m => {
|
|
||||||
if (
|
|
||||||
(
|
|
||||||
m.type === 'childList' &&
|
|
||||||
(
|
|
||||||
isHeaderElement(m.target) ||
|
|
||||||
isHeaderElement(m.addedNodes[0]) ||
|
|
||||||
isHeaderElement(m.removedNodes[0])
|
|
||||||
)
|
|
||||||
) ||
|
|
||||||
(
|
|
||||||
m.type === 'characterData' &&
|
|
||||||
isHeaderElement(m.target.parentElement)
|
|
||||||
)
|
|
||||||
) findHeaders();
|
|
||||||
})
|
|
||||||
});
|
|
||||||
function startContentObserver() {
|
|
||||||
findHeaders();
|
|
||||||
contentObserver.disconnect();
|
|
||||||
contentObserver.observe(
|
|
||||||
document.querySelector('.notion-page-content'),
|
|
||||||
{
|
|
||||||
childList: true,
|
|
||||||
subtree: true,
|
|
||||||
characterData: true,
|
|
||||||
}
|
}
|
||||||
);
|
// Clear outline on database pages
|
||||||
|
else if (addedNodes[0].className === 'notion-scroller') {
|
||||||
|
contentObserver.disconnect();
|
||||||
|
const outline = document.querySelector('.outliner');
|
||||||
|
if (outline) outline.textContent = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Observe for header changes
|
||||||
|
const contentObserver = new MutationObserver((list, observer) => {
|
||||||
|
list.forEach(m => {
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
m.type === 'childList' &&
|
||||||
|
(
|
||||||
|
isHeaderElement(m.target) ||
|
||||||
|
isHeaderElement(m.addedNodes[0]) ||
|
||||||
|
isHeaderElement(m.removedNodes[0])
|
||||||
|
)
|
||||||
|
) ||
|
||||||
|
(
|
||||||
|
m.type === 'characterData' &&
|
||||||
|
isHeaderElement(m.target.parentElement)
|
||||||
|
)
|
||||||
|
) findHeaders();
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
function startContentObserver() {
|
||||||
|
findHeaders();
|
||||||
|
contentObserver.disconnect();
|
||||||
|
contentObserver.observe(
|
||||||
|
document.querySelector('.notion-page-content'),
|
||||||
|
{
|
||||||
|
childList: true,
|
||||||
|
subtree: true,
|
||||||
|
characterData: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function findHeaders() {
|
function findHeaders() {
|
||||||
const outline = document.querySelector('.outliner');
|
const outline = document.querySelector('.outliner');
|
||||||
if (!outline) {
|
if (!outline) return;
|
||||||
pageObserver.disconnect();
|
|
||||||
observer.disconnect();
|
|
||||||
}
|
|
||||||
outline.textContent = '';
|
outline.textContent = '';
|
||||||
|
|
||||||
const pageContent = document.querySelector('.notion-page-content');
|
const pageContent = document.querySelector('.notion-page-content');
|
||||||
@ -111,5 +98,20 @@ module.exports = (store) => {
|
|||||||
return placeholder.includes('Heading');
|
return placeholder.includes('Heading');
|
||||||
}
|
}
|
||||||
|
|
||||||
return initOutliner;
|
return {
|
||||||
}
|
onLoad() {
|
||||||
|
// Find headers when switching panels
|
||||||
|
if (document.querySelector('.notion-page-content')) {
|
||||||
|
startContentObserver();
|
||||||
|
};
|
||||||
|
pageObserver.observe(document.body, {
|
||||||
|
childList: true,
|
||||||
|
subtree: true,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onSwitch() {
|
||||||
|
pageObserver.disconnect();
|
||||||
|
contentObserver.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user