Last active
September 18, 2020 11:06
-
-
Save mnmaraes/523d006a1663b55784d7eb6d4d086cac to your computer and use it in GitHub Desktop.
Roam Focus mode toggle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const body = document.querySelector(".roam-body-main"); | |
| function setCenterFocus() { | |
| selectors = [".roam-article", ".roam-topbar", "#buffer"] | |
| const hasSidebar = document.querySelector("#roam-right-sidebar-content") != null; | |
| selectors.map(sel => document.querySelector(sel)).filter(el => el).forEach(el => { | |
| console.log("Ping!"); | |
| if (hasSidebar) { | |
| el.classList.remove("patch-roam-focus"); | |
| } else { | |
| el.classList.add("patch-roam-focus"); | |
| } | |
| }) | |
| } | |
| const observer = new MutationObserver(setCenterFocus); | |
| setCenterFocus(); | |
| observer.observe(body, {subtree: true, childList: true}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment