aboutsummaryrefslogtreecommitdiffstats
path: root/static/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/app.js')
-rw-r--r--static/app.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/static/app.js b/static/app.js
index b89fbaa..e2da02a 100644
--- a/static/app.js
+++ b/static/app.js
@@ -230,6 +230,28 @@ tabBody.addEventListener("pointerup", (e) => {
});
tabBody.addEventListener("pointercancel", () => { swipe = null; });
+// theme.css is rendered per request from UDT's live files, so re-reading it
+// carries a scheme, wallpaper or font-size change to an open page. The <style>
+// comes after the <link>, so it wins once filled.
+const themeStyle = document.head.appendChild(document.createElement("style"));
+const themeColor = document.querySelector('meta[name="theme-color"]');
+
+async function refreshTheme() {
+ try {
+ const r = await fetch("theme.css", { cache: "no-store" });
+ if (!r.ok) return;
+ const text = await r.text();
+ if (text !== themeStyle.textContent) themeStyle.textContent = text;
+ } catch {
+ // keep the current theme; the next tick retries
+ }
+ const base = getComputedStyle(document.documentElement).getPropertyValue("--udt-base").trim();
+ if (base) themeColor.content = base;
+}
+refreshers.push(refreshTheme);
+refreshTheme();
+setInterval(refreshTheme, 5000);
+
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "visible") refreshers.forEach((fn) => fn());
});