Add percentage distance option

This commit is contained in:
CloudHill 2020-10-20 22:44:43 +07:00
parent d9ad6aca43
commit 980528699e

View File

@ -27,7 +27,13 @@ module.exports = {
key: "top", key: "top",
label: "scroll down distance to show button", label: "scroll down distance to show button",
type: "input", type: "input",
value: 100, value: 80,
},
{
key: "percent",
label: "set distance as a percentage",
type: "toggle",
value: true,
}, },
], ],
hacks: { hacks: {
@ -78,13 +84,18 @@ module.exports = {
addedNodes[0].className === 'notion-scroller' addedNodes[0].className === 'notion-scroller'
) )
) { ) {
if (store().top> 0) { let top = store().top;
if (top> 0) {
scroll.classList.add('hidden'); scroll.classList.add('hidden');
if (store().percent) {
top *= document.querySelector('.notion-page-content').offsetHeight / 100;
}
document document
.querySelector('.notion-frame > .notion-scroller') .querySelector('.notion-frame > .notion-scroller')
.addEventListener('scroll', (event) => { .addEventListener('scroll', (event) => {
if (event.target.scrollTop < store().top) if (event.target.scrollTop < top)
scroll.classList.add('hidden'); scroll.classList.add('hidden');
else else
scroll.classList.remove('hidden'); scroll.classList.remove('hidden');