Skip to content

Instantly share code, notes, and snippets.

@mnmaraes
Last active September 18, 2020 11:06
Show Gist options
  • Select an option

  • Save mnmaraes/523d006a1663b55784d7eb6d4d086cac to your computer and use it in GitHub Desktop.

Select an option

Save mnmaraes/523d006a1663b55784d7eb6d4d086cac to your computer and use it in GitHub Desktop.
Roam Focus mode toggle
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