Spaces:
Running
Running
Download theme.js from BoevaLab/Gene-Embedding-Hub: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/spaces/BoevaLab/Gene-Embedding-Hub/resolve/main/theme.js
- Command line
-
hf download hf://spaces/BoevaLab/Gene-Embedding-Hub/theme.js
-
curl -L -o theme.js https://huggingface.co/spaces/BoevaLab/Gene-Embedding-Hub/resolve/main/theme.js
1.42 kB
| (() => { | |
| "use strict"; | |
| const storageKey = "gene-embeddings-theme"; | |
| const root = document.documentElement; | |
| const button = document.getElementById("theme-toggle"); | |
| if (!button) { | |
| return; | |
| } | |
| function readSavedTheme() { | |
| try { | |
| return window.localStorage.getItem(storageKey); | |
| } catch { | |
| return null; | |
| } | |
| } | |
| function saveTheme(theme) { | |
| try { | |
| window.localStorage.setItem(storageKey, theme); | |
| } catch { | |
| // The toggle still works when browser storage is unavailable. | |
| } | |
| } | |
| function applyTheme(theme) { | |
| const night = theme === "night"; | |
| root.dataset.theme = night ? "night" : "day"; | |
| button.textContent = night | |
| ? "🌙" | |
| : "☀️"; | |
| button.setAttribute( | |
| "aria-pressed", | |
| String(night), | |
| ); | |
| button.setAttribute( | |
| "aria-label", | |
| night | |
| ? "Current theme: dark. Switch to light theme" | |
| : "Current theme: light. Switch to dark theme", | |
| ); | |
| button.setAttribute( | |
| "title", | |
| night | |
| ? "Switch to light theme" | |
| : "Switch to dark theme", | |
| ); | |
| } | |
| const savedTheme = readSavedTheme(); | |
| applyTheme( | |
| savedTheme === "night" | |
| ? "night" | |
| : "day", | |
| ); | |
| button.addEventListener("click", () => { | |
| const nextTheme = | |
| root.dataset.theme === "night" | |
| ? "day" | |
| : "night"; | |
| applyTheme(nextTheme); | |
| saveTheme(nextTheme); | |
| }); | |
| })(); | |