diff options
| author | Fuwn <[email protected]> | 2026-04-01 11:02:59 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-04-01 11:02:59 +0000 |
| commit | 9c98a399632b5cbe4be11350d72b84cb8fcbace9 (patch) | |
| tree | 9278067a3f743a2c9504d80d1f277c1eb8d0a6df /src/stores | |
| parent | fix(badges): hide outbound link notice (diff) | |
| download | due.moe-9c98a399632b5cbe4be11350d72b84cb8fcbace9.tar.xz due.moe-9c98a399632b5cbe4be11350d72b84cb8fcbace9.zip | |
feat(ui): add april fools executive mode
Diffstat (limited to 'src/stores')
| -rw-r--r-- | src/stores/aprilFools.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/stores/aprilFools.ts b/src/stores/aprilFools.ts new file mode 100644 index 00000000..d86829c1 --- /dev/null +++ b/src/stores/aprilFools.ts @@ -0,0 +1,37 @@ +import { browser } from "$app/environment"; +import { writable } from "svelte/store"; + +const storageKey = (date = new Date()) => + `aprilFoolsExecutiveMode:${date.getFullYear()}`; + +export const isAprilFoolsDay = (date = new Date()) => + date.getMonth() === 3 && date.getDate() === 1; + +let hydrated = !browser; + +const store = writable(false); + +export const hydrateAprilFools = () => { + if (!browser || hydrated) return; + + const storedValue = localStorage.getItem(storageKey()); + + store.set(storedValue === null ? isAprilFoolsDay() : storedValue === "true"); + hydrated = true; +}; + +store.subscribe((value) => { + if (!browser || !hydrated) return; + + localStorage.setItem(storageKey(), String(value)); +}); + +export const aprilFoolsVisible = () => isAprilFoolsDay(); + +const aprilFools = { + subscribe: store.subscribe, + set: store.set, + toggle: () => store.update((value) => !value), +}; + +export default aprilFools; |