Skip to content

Commit 2cfcf3f

Browse files
committed
Add ?theme= URL param for temporary theme forcing, redirect HN referrers to it
1 parent 018f6f0 commit 2cfcf3f

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

src/scripts/theme-init.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,42 @@
22
// Depends on theme-shared.js being loaded first
33

44
const T = window.ThemeUtils;
5+
6+
// Redirect HN referrers to ?theme=geocities so the URL reflects the theme
57
const isFromHN = document.referrer.includes("news.ycombinator.com");
6-
const theme = isFromHN
7-
? "geocities"
8-
: localStorage.getItem("theme") || "system";
8+
if (isFromHN && !new URLSearchParams(window.location.search).has("theme")) {
9+
window.location.search = "?theme=geocities";
10+
}
11+
12+
// All valid theme values (standard + hotdog variants + meta themes)
13+
const VALID_THEMES = [
14+
"system",
15+
"light",
16+
"dark",
17+
"oled",
18+
"terminal",
19+
"gameboy",
20+
"halflife",
21+
"vaporwave",
22+
"synthwave",
23+
"hotdog-ketchup",
24+
"hotdog-mustard",
25+
"shuffle",
26+
"chaos",
27+
"shifting",
28+
"cursed",
29+
"geocities",
30+
];
31+
32+
function urlTheme(): string | null {
33+
const param = new URLSearchParams(window.location.search).get("theme");
34+
if (param && VALID_THEMES.includes(param)) {
35+
return param;
36+
}
37+
return null;
38+
}
39+
40+
const theme = urlTheme() || localStorage.getItem("theme") || "system";
941
let activeTheme = theme;
1042
const themes = "__CHAOS_THEMES__".split(",");
1143

0 commit comments

Comments
 (0)