From 980528699e8825a9ad2efe34923f4351d9683081 Mon Sep 17 00:00:00 2001 From: CloudHill Date: Tue, 20 Oct 2020 22:44:43 +0700 Subject: [PATCH] Add percentage distance option --- mods/scroll-to-top/mod.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/mods/scroll-to-top/mod.js b/mods/scroll-to-top/mod.js index c8a68f0..090a6cb 100644 --- a/mods/scroll-to-top/mod.js +++ b/mods/scroll-to-top/mod.js @@ -27,7 +27,13 @@ module.exports = { key: "top", label: "scroll down distance to show button", type: "input", - value: 100, + value: 80, + }, + { + key: "percent", + label: "set distance as a percentage", + type: "toggle", + value: true, }, ], hacks: { @@ -78,13 +84,18 @@ module.exports = { addedNodes[0].className === 'notion-scroller' ) ) { - if (store().top> 0) { + let top = store().top; + if (top> 0) { scroll.classList.add('hidden'); - + + if (store().percent) { + top *= document.querySelector('.notion-page-content').offsetHeight / 100; + } + document .querySelector('.notion-frame > .notion-scroller') .addEventListener('scroll', (event) => { - if (event.target.scrollTop < store().top) + if (event.target.scrollTop < top) scroll.classList.add('hidden'); else scroll.classList.remove('hidden');