From c1ca9f1e144af3406297421a73b4905594130b74 Mon Sep 17 00:00:00 2001 From: David Varon Date: Fri, 20 Nov 2020 11:46:09 -0500 Subject: [PATCH] init commit --- mods/sticky-toc/mod.js | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 mods/sticky-toc/mod.js diff --git a/mods/sticky-toc/mod.js b/mods/sticky-toc/mod.js new file mode 100644 index 0000000..5cd1c4c --- /dev/null +++ b/mods/sticky-toc/mod.js @@ -0,0 +1,49 @@ +/* + * sticky toc + * (c) 2020 varontron + * under the MIT license + */ + +'use strict'; + + +module.exports = { + id: '3d1b03fe-a847-45bd-a317-7f082546abab', + tags: ['extension'], + name: 'sticky toc', + desc: + `Sticks a table of contents in place (no scroll) when it's put in a column`, + version: '0.1.0', + author: 'varontron', + hacks: { + 'renderer/preload.js'(store, __exports) { + document.addEventListener('readystatechange', (event) => { + if (document.readyState !== 'complete') return false; + const attempt_interval = setInterval(enhance, 500) + function enhance() { + const notion_elem = document.querySelector('.notion-frame') + if (!notion_elem) return; + clearInterval(attempt_interval) + + handle(); + const observer = new MutationObserver(handle); + observer.observe(notion_elem, { + childList: true, + subtree: true, + }) + + function handle(list, observer) { + const toc = document.querySelector('.notion-table_of_contents-block') + if (toc !== null + && toc.parentElement.style.position === 'sticky') return; + if (toc !== null && toc.closest('.notion-column-block') !== null) + { + let origCss = toc.parentElement.style.cssText + toc.parentElement.style.cssText = `${origCss} position:sticky; top: 0; align-self: flex-start;` + } + } + } + }) + } + } +};