Added scroll down distance option

This commit is contained in:
CloudHill 2020-10-20 22:20:55 +07:00
parent 70e6dcf249
commit c87917abba

View File

@ -23,6 +23,12 @@ module.exports = {
type: "toggle", type: "toggle",
value: true, value: true,
}, },
{
key: "top",
label: "scroll down distance to show button",
type: "input",
value: 100,
},
], ],
hacks: { hacks: {
"renderer/preload.js"(store, __exports) { "renderer/preload.js"(store, __exports) {
@ -53,6 +59,40 @@ module.exports = {
behavior: store().smooth ? 'smooth' : 'auto', behavior: store().smooth ? 'smooth' : 'auto',
}); });
}) })
let queue = [];
const observer = new MutationObserver((list, observer) => {
if (!queue.length) requestAnimationFrame(() => process(queue));
queue.push(...list);
});
observer.observe(document.body, {
childList: true,
subtree: true,
});
function process(list) {
queue = [];
for (let { addedNodes } of list) {
if (
addedNodes[0] && (
addedNodes[0].className === 'notion-page-content' ||
addedNodes[0].className === 'notion-scroller'
)
) {
if (store().top> 0) {
scroll.classList.add('hidden');
document
.querySelector('.notion-frame > .notion-scroller')
.addEventListener('scroll', (event) => {
if (event.target.scrollTop < store().top)
scroll.classList.add('hidden');
else
scroll.classList.remove('hidden');
})
}
}
}
}
} }
}); });
} }