summaryrefslogtreecommitdiff
path: root/public/theme.js
blob: 90bd1ded736a02d8d9baebec9cb942ef6f5c7fde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
async function applyStyle(path, name) {
  const res = await fetch(`${path}/${encodeURIComponent(name)}`);
  if (!res.ok) return false;
  for (const [key, value] of Object.entries(await res.json())) {
    document.documentElement.style.setProperty(`--${key}`, value);
  }
  return true;
}

window.setStyle = (path, name) => applyStyle(path, name);
window.setTheme = (name) => applyStyle("/theme", name);
window.setFontPack = (name) => applyStyle("/font-pack", name);