Skip to content

Instantly share code, notes, and snippets.

@rszyma
Last active February 9, 2022 22:45
Show Gist options
  • Save rszyma/7e448b911da2f397f0bcf792fcf32772 to your computer and use it in GitHub Desktop.
Save rszyma/7e448b911da2f397f0bcf792fcf32772 to your computer and use it in GitHub Desktop.
Obsidian css + javascript mod to auto hide titlebar when the window is maximized.

Installation:

  1. Enable CSS Snippets: Options > Appearance > CSS Snippets
  2. Create a new css file in the snippets folder with the following content:
.body-fullscreen {
  padding-top: 0 !important;
}
.titlebar-fullscreen {
  display: none !important;
}
  1. Disable Safe Mode: Options > Community plugins > Safe mode
  2. Install obsidian-javascript-init plugin (obsidian link: obsidian://show-plugin?id=obsidian-javascript-init)
  3. Enable JavaScript Init plugin
  4. In Plugin options > JavaScript Init Setting paste the following code:
body = document.querySelector("body");
titlebar = document.querySelector(".titlebar");

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

let resizeObserver = new ResizeObserver((entries) => {
  handleResized()
});
resizeObserver.observe(body);

function handleResized() {
  sleep(50).then(() => {
    if (screenX == 0) {
      body.classList.add("body-fullscreen");
      titlebar.classList.add("titlebar-fullscreen");
    }
    else {
      body.classList.remove("body-fullscreen");
      titlebar.classList.remove("titlebar-fullscreen");
    }
  })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment