wemathallday 0.0.0-stage → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.html +1963 -0
- package/loader.svg +67 -0
- package/package.json +12 -4
- package/README.md +0 -3
package/index.html
ADDED
|
@@ -0,0 +1,1963 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
|
6
|
+
<title>mlv2</title>
|
|
7
|
+
<meta name="description" content="mlv2: a small, fast library of games." />
|
|
8
|
+
<meta name="color-scheme" content="dark" />
|
|
9
|
+
<meta name="theme-color" content="#000000" />
|
|
10
|
+
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='7' fill='%23000'/%3E%3Ccircle cx='16' cy='16' r='7' fill='%23f01a36'/%3E%3Ccircle cx='14' cy='13' r='2.2' fill='%23fff' opacity='.7'/%3E%3C/svg%3E" />
|
|
11
|
+
|
|
12
|
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
13
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
14
|
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
|
|
15
|
+
|
|
16
|
+
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
|
|
17
|
+
<style type="text/tailwindcss">
|
|
18
|
+
/*
|
|
19
|
+
Design language: void black + ambient colour glow, glass on every floating layer,
|
|
20
|
+
glossy "inflated" candy elements (orbs, badges, chips, buttons, hero shapes).
|
|
21
|
+
Brand red-pink is the lead; orange / lime / blue / purple are category colours.
|
|
22
|
+
*/
|
|
23
|
+
@theme {
|
|
24
|
+
--font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", ui-sans-serif, system-ui, sans-serif;
|
|
25
|
+
--font-mono: ui-monospace, "SF Mono", Menlo, monospace;
|
|
26
|
+
--color-ink-950: #000000; --color-ink-900: #0a0a0b; --color-ink-850: #101012; --color-ink-800: #161618;
|
|
27
|
+
--color-ink-700: #232326; --color-ink-600: #2c2c30; --color-ink-500: #48484c; --color-ink-400: #8e8e93;
|
|
28
|
+
--color-ink-300: #a1a1a6; --color-ink-200: #c7c7cc; --color-ink-100: #e5e5ea; --color-ink-50: #f5f5f7;
|
|
29
|
+
--color-red-700: #8f0e20; --color-red-600: #c11228; --color-red-500: #f01a36; --color-red-400: #ff4d63; --color-red-300: #ff8b96;
|
|
30
|
+
}
|
|
31
|
+
@layer components {
|
|
32
|
+
.btn { @apply inline-flex h-11 items-center justify-center rounded-full px-5 text-[15px] font-semibold transition-[background-color,filter,transform] duration-200 active:scale-[0.97] disabled:opacity-50 sm:h-9 sm:text-[14px]; }
|
|
33
|
+
.icon-btn { @apply grid h-11 w-11 shrink-0 place-items-center rounded-full text-ink-200 transition-colors duration-200 hover:text-white sm:h-9 sm:w-9; }
|
|
34
|
+
.field { @apply h-11 w-full rounded-[12px] bg-white/[0.07] px-3 text-[16px] text-ink-50 ring-1 ring-inset ring-white/10 transition-shadow duration-200 placeholder:text-ink-400 focus:ring-2 focus:ring-red-500 sm:h-9 sm:text-[14px]; }
|
|
35
|
+
.chip { @apply inline-flex h-10 shrink-0 items-center gap-2 whitespace-nowrap rounded-full pl-4 pr-1.5 text-[14px] font-medium transition-colors duration-200 sm:h-9; }
|
|
36
|
+
}
|
|
37
|
+
</style>
|
|
38
|
+
|
|
39
|
+
<style>
|
|
40
|
+
html { background: #000; }
|
|
41
|
+
body { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
|
|
42
|
+
::selection { background: rgba(240,26,54,0.4); color: #fff; }
|
|
43
|
+
input { caret-color: var(--color-red-400); }
|
|
44
|
+
:focus-visible { outline: 2px solid var(--color-red-400); outline-offset: 2px; }
|
|
45
|
+
.field:focus-visible, [data-pin-idx]:focus-visible { outline: none; }
|
|
46
|
+
[tabindex="-1"]:focus { outline: none; }
|
|
47
|
+
.tile:focus-visible { outline: none; }
|
|
48
|
+
.tile:focus-visible .tile-icon { outline: 2px solid var(--color-red-400); outline-offset: 3px; }
|
|
49
|
+
.page-x { padding-left: max(1.25rem, env(safe-area-inset-left)); padding-right: max(1.25rem, env(safe-area-inset-right)); }
|
|
50
|
+
.tile-img { outline: 1px solid rgba(255,255,255,0.1); outline-offset: -1px; }
|
|
51
|
+
|
|
52
|
+
/* ---------- ambient colour: gives the glass something to refract ---------- */
|
|
53
|
+
.ambient { position: fixed; inset: 0; z-index: 0; pointer-events: none;
|
|
54
|
+
background:
|
|
55
|
+
radial-gradient(680px 420px at 85% 2%, rgba(240,26,54,0.11), transparent 70%),
|
|
56
|
+
radial-gradient(720px 520px at 8% 108%, rgba(240,26,54,0.06), transparent 70%); }
|
|
57
|
+
|
|
58
|
+
/* ---------- liquid glass ---------- */
|
|
59
|
+
.glass { background: rgba(255,255,255,0.05); -webkit-backdrop-filter: blur(24px) saturate(180%); backdrop-filter: blur(24px) saturate(180%);
|
|
60
|
+
box-shadow: inset 0 1px 0 rgba(255,255,255,0.12), 0 10px 32px rgba(0,0,0,0.4); }
|
|
61
|
+
.glass-sheet { background: rgba(28,28,31,0.55); -webkit-backdrop-filter: blur(40px) saturate(180%); backdrop-filter: blur(40px) saturate(180%); }
|
|
62
|
+
.glass::before { content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1px; pointer-events: none;
|
|
63
|
+
background: linear-gradient(135deg, rgba(255,255,255,0.16), rgba(255,255,255,0.03) 40%, rgba(255,255,255,0.03) 60%, rgba(255,255,255,0.09));
|
|
64
|
+
-webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; }
|
|
65
|
+
.glass-lite { background: rgba(255,255,255,0.07); box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), inset 0 0 0 1px rgba(255,255,255,0.08); }
|
|
66
|
+
.glass-lite:hover { background: rgba(255,255,255,0.12); }
|
|
67
|
+
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { .glass { background: rgba(22,22,24,0.94); } .glass-sheet { background: rgba(18,18,20,0.97); } }
|
|
68
|
+
@media (prefers-reduced-transparency: reduce) { .glass, .glass-sheet { -webkit-backdrop-filter: none; backdrop-filter: none; background: #161618; } }
|
|
69
|
+
|
|
70
|
+
/* ---------- bubbly / inflated ---------- */
|
|
71
|
+
.orb { width: 14px; height: 14px; border-radius: 999px; flex-shrink: 0;
|
|
72
|
+
background: radial-gradient(circle at 32% 28%, #fff 0 12%, #ff7a8a 28%, #f01a36 62%, #a30c22);
|
|
73
|
+
box-shadow: 0 0 14px rgba(240,26,54,0.8), inset 0 -2px 3px rgba(0,0,0,0.25); }
|
|
74
|
+
.badge { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 14px 0 10px; border-radius: 999px; font-size: 13px; font-weight: 600; color: #fff;
|
|
75
|
+
background: linear-gradient(180deg, #ff6b7d, #f01a36 60%, #c80f27);
|
|
76
|
+
box-shadow: inset 0 1px 0 rgba(255,255,255,0.55), inset 0 -2px 0 rgba(0,0,0,0.16), 0 6px 22px -2px rgba(240,26,54,0.7); }
|
|
77
|
+
.glow-line { display: inline-block; padding: 0 0 0.1em;
|
|
78
|
+
background: linear-gradient(180deg, #ffb8c0 0%, #ff4d63 48%, #f01a36 100%); -webkit-background-clip: text; background-clip: text; color: transparent; }
|
|
79
|
+
.btn-primary { color: #fff; background: linear-gradient(180deg, #ff6b7d, #f01a36 55%, #c80f27);
|
|
80
|
+
box-shadow: inset 0 1px 0 rgba(255,255,255,0.5), inset 0 -2px 0 rgba(0,0,0,0.18), 0 8px 22px -6px rgba(240,26,54,0.7); }
|
|
81
|
+
.btn-primary:hover { filter: brightness(1.08); }
|
|
82
|
+
.btn-ghost { color: var(--color-ink-50); background: rgba(255,255,255,0.08); box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), inset 0 0 0 1px rgba(255,255,255,0.08); }
|
|
83
|
+
.btn-ghost:hover { background: rgba(255,255,255,0.14); }
|
|
84
|
+
.chip-on { background: linear-gradient(180deg, #ff6b7d, #f01a36 60%, #c80f27);
|
|
85
|
+
box-shadow: inset 0 1px 0 rgba(255,255,255,0.5), inset 0 -2px 0 rgba(0,0,0,0.16), 0 6px 20px -4px rgba(240,26,54,0.65); }
|
|
86
|
+
.chip-count { display: grid; place-items: center; min-width: 26px; height: 26px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 700; color: #fff; background: #c11228;
|
|
87
|
+
box-shadow: inset 0 1px 0 rgba(255,255,255,0.3); }
|
|
88
|
+
.chip-on .chip-count { background: #fff; color: #b50e28; box-shadow: none; }
|
|
89
|
+
|
|
90
|
+
/* game tiles: glass card, glossy icon, glow in the category colour */
|
|
91
|
+
.tile { background: rgba(255,255,255,0.05); border-radius: 28px; padding: 10px 10px 12px;
|
|
92
|
+
box-shadow: inset 0 1px 0 rgba(255,255,255,0.16), inset 0 0 0 1px rgba(255,255,255,0.07);
|
|
93
|
+
transition: background-color .3s ease-out, box-shadow .3s ease-out; }
|
|
94
|
+
.tile:hover { background: rgba(255,255,255,0.09); box-shadow: inset 0 1px 0 rgba(255,255,255,0.28), inset 0 0 0 1px rgba(240,26,54,0.55); }
|
|
95
|
+
.tile-icon { position: relative; }
|
|
96
|
+
.tile-icon::after { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
|
|
97
|
+
background: linear-gradient(160deg, rgba(255,255,255,0.3), rgba(255,255,255,0) 42%);
|
|
98
|
+
box-shadow: inset 0 2px 0 rgba(255,255,255,0.35), inset 0 -8px 14px rgba(0,0,0,0.25); }
|
|
99
|
+
|
|
100
|
+
/* hero shapes */
|
|
101
|
+
.float { display: block; width: 100%; height: auto; aspect-ratio: 1; filter: drop-shadow(0 14px 22px var(--g)); transform: rotate(var(--r, 0deg));
|
|
102
|
+
animation: float 6s ease-in-out infinite; animation-delay: var(--d, 0s); }
|
|
103
|
+
@keyframes float { 0%, 100% { transform: translateY(0) rotate(var(--r, 0deg)); } 50% { transform: translateY(-12px) rotate(calc(var(--r, 0deg) + 4deg)); } }
|
|
104
|
+
|
|
105
|
+
/* ---------- accessibility + admin controls ---------- */
|
|
106
|
+
.skip { position: fixed; left: 12px; top: -64px; z-index: 100; padding: 10px 16px; border-radius: 999px; background: #fff; color: #000; font-size: 14px; font-weight: 600; transition: top .2s; }
|
|
107
|
+
.skip:focus { top: calc(env(safe-area-inset-top) + 12px); }
|
|
108
|
+
input[type="search"]::-webkit-search-cancel-button { display: none; }
|
|
109
|
+
input[type="file"]:focus-visible, input[type="checkbox"]:focus-visible { outline: 2px solid var(--color-red-400); outline-offset: 2px; }
|
|
110
|
+
.btn-danger { color: #fff; background: #c11228; box-shadow: inset 0 1px 0 rgba(255,255,255,0.25); }
|
|
111
|
+
.btn-danger:hover { background: #d61a40; }
|
|
112
|
+
.tag { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; color: var(--color-ink-200); background: rgba(255,255,255,0.1); vertical-align: 1px; }
|
|
113
|
+
.switch { appearance: none; -webkit-appearance: none; position: relative; flex-shrink: 0; width: 44px; height: 26px; border-radius: 999px; cursor: pointer;
|
|
114
|
+
background: rgba(255,255,255,0.16); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12); transition: background-color .2s; }
|
|
115
|
+
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.4); transition: transform .25s cubic-bezier(.34,1.56,.64,1); }
|
|
116
|
+
.switch:checked { background: #f01a36; }
|
|
117
|
+
.switch:checked::after { transform: translateX(18px); }
|
|
118
|
+
.switch:disabled, button:disabled { opacity: 0.45; cursor: not-allowed; }
|
|
119
|
+
|
|
120
|
+
/* ---------- top bar: same recipe as the game cards so it blends in ---------- */
|
|
121
|
+
.topbar { background: rgba(255,255,255,0.045); -webkit-backdrop-filter: blur(20px) saturate(160%); backdrop-filter: blur(20px) saturate(160%);
|
|
122
|
+
box-shadow: inset 0 0 0 1px rgba(255,255,255,0.09); }
|
|
123
|
+
.topbar .field { background: rgba(255,255,255,0.05); }
|
|
124
|
+
|
|
125
|
+
/* ---------- settings + tabs ---------- */
|
|
126
|
+
.tab { height: 36px; padding: 0 14px; border-radius: 999px; font-size: 14px; font-weight: 500; color: var(--color-ink-300); transition: background-color .2s, color .2s; }
|
|
127
|
+
.tab:hover { color: #fff; }
|
|
128
|
+
.tab[aria-selected="true"] { background: rgba(255,255,255,0.14); color: #fff; }
|
|
129
|
+
.shead { margin: 22px 4px 8px; font-size: 13px; font-weight: 600; color: var(--color-ink-300); }
|
|
130
|
+
.shead:first-child { margin-top: 6px; }
|
|
131
|
+
.sgroup { border-radius: 20px; padding: 2px 16px; background: rgba(255,255,255,0.05); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08); }
|
|
132
|
+
.srow { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 0; border-bottom: 1px solid rgba(255,255,255,0.07); cursor: pointer; }
|
|
133
|
+
.srow.plain { cursor: default; }
|
|
134
|
+
.sgroup > .srow:last-child, .sgroup > div:last-child { border-bottom: 0; }
|
|
135
|
+
.opt { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 18px; cursor: pointer; background: rgba(255,255,255,0.05); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08); }
|
|
136
|
+
.opt:hover { background: rgba(255,255,255,0.08); }
|
|
137
|
+
.opt:has(input:checked) { background: rgba(240,26,54,0.16); box-shadow: inset 0 0 0 1.5px rgba(240,26,54,0.75); }
|
|
138
|
+
.opt:has(input:focus-visible), .pill-opt:has(input:focus-visible) { outline: 2px solid var(--color-red-400); outline-offset: 2px; }
|
|
139
|
+
.pill-opt { cursor: pointer; border-radius: 999px; font-size: 13px; font-weight: 500; color: var(--color-ink-200); }
|
|
140
|
+
.pill-opt span { display: block; padding: 7px 12px; border-radius: 999px; }
|
|
141
|
+
.pill-opt:has(input:checked) span { background: rgba(255,255,255,0.16); color: #fff; }
|
|
142
|
+
kbd { font-family: var(--font-mono); font-size: 13px; }
|
|
143
|
+
html.rm *, html.rm *::before, html.rm *::after { animation: none !important; transition-duration: 0.01ms !important; }
|
|
144
|
+
html.rm .tile-icon { transform: none; }
|
|
145
|
+
|
|
146
|
+
/* ---------- motion ---------- */
|
|
147
|
+
.w { display: inline-block; opacity: 0; }
|
|
148
|
+
.glowwrap { display: inline-block; filter: drop-shadow(0 0 22px rgba(240,26,54,0.55)); }
|
|
149
|
+
.shape { position: absolute; opacity: 0; }
|
|
150
|
+
.par { will-change: transform; }
|
|
151
|
+
.ambient { animation: breathe 10s ease-in-out infinite; }
|
|
152
|
+
@keyframes breathe { 0%, 100% { opacity: 0.75; } 50% { opacity: 1; } }
|
|
153
|
+
.badge { position: relative; overflow: hidden; }
|
|
154
|
+
.badge::after { content: ""; position: absolute; inset: 0; pointer-events: none;
|
|
155
|
+
background: linear-gradient(105deg, transparent 35%, rgba(255,255,255,0.6) 50%, transparent 65%);
|
|
156
|
+
transform: translateX(-120%); animation: sheen 4.5s ease-in-out 1.6s infinite; }
|
|
157
|
+
@keyframes sheen { 0%, 55% { transform: translateX(-120%); } 100% { transform: translateX(120%); } }
|
|
158
|
+
.shimmer { background: linear-gradient(100deg, #161618 30%, #242428 50%, #161618 70%); background-size: 220% 100%; animation: shimmer 1.4s linear infinite; }
|
|
159
|
+
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }
|
|
160
|
+
#search-wrap { width: 100%; max-width: 16rem; transition: max-width .4s cubic-bezier(.22,1,.36,1); }
|
|
161
|
+
#search-wrap:focus-within { max-width: 22rem; }
|
|
162
|
+
.chip { transition: translate .2s ease-out, background-color .2s, color .2s; }
|
|
163
|
+
.chip:hover { translate: 0 -2px; }
|
|
164
|
+
.chip:active { scale: .94; }
|
|
165
|
+
.tile { position: relative; }
|
|
166
|
+
.tile::before { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; opacity: 0; transition: opacity .3s;
|
|
167
|
+
background: radial-gradient(170px circle at var(--mx, 50%) var(--my, 50%), rgba(255,255,255,0.15), transparent 70%); }
|
|
168
|
+
.tile:hover::before { opacity: 1; }
|
|
169
|
+
.tile-icon { transform: perspective(700px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)); transition-timing-function: cubic-bezier(.34,1.56,.64,1); }
|
|
170
|
+
.tile.moving .tile-icon { transition-duration: .12s; transition-timing-function: ease-out; }
|
|
171
|
+
.pulse-orb { animation: pulse-orb 1.2s ease-in-out infinite; }
|
|
172
|
+
@keyframes pulse-orb { 0%, 100% { transform: scale(.8); opacity: .6; } 50% { transform: scale(1.25); opacity: 1; } }
|
|
173
|
+
@media (prefers-reduced-motion: reduce) { .ambient, .badge::after, .shimmer, .pulse-orb { animation: none; } .tile-icon { transform: none; } }
|
|
174
|
+
|
|
175
|
+
.no-scrollbar { scrollbar-width: none; }
|
|
176
|
+
.no-scrollbar::-webkit-scrollbar { display: none; }
|
|
177
|
+
* { scrollbar-width: thin; scrollbar-color: #2c2c30 transparent; }
|
|
178
|
+
*::-webkit-scrollbar { width: 8px; height: 8px; }
|
|
179
|
+
*::-webkit-scrollbar-thumb { background: #2c2c30; border-radius: 999px; }
|
|
180
|
+
|
|
181
|
+
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
|
182
|
+
.rise { animation: rise 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94) both; animation-delay: var(--d, 0s); }
|
|
183
|
+
@media (prefers-reduced-motion: reduce) { .rise, .float { animation: none; } }
|
|
184
|
+
</style>
|
|
185
|
+
</head>
|
|
186
|
+
|
|
187
|
+
<body class="min-h-screen bg-ink-950 font-sans text-ink-50 antialiased">
|
|
188
|
+
|
|
189
|
+
<a href="#games-heading" class="skip">Skip to games</a>
|
|
190
|
+
|
|
191
|
+
<div class="ambient" aria-hidden="true"></div>
|
|
192
|
+
|
|
193
|
+
<button id="panic-btn" type="button" hidden aria-label="Panic: leave this page now" title="Panic: leave this page now" class="glass-lite icon-btn fixed bottom-4 left-4 z-[45] opacity-70 hover:opacity-100">
|
|
194
|
+
<svg class="h-[18px] w-[18px]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><path d="m16 17 5-5-5-5"/><path d="M21 12H9"/></svg>
|
|
195
|
+
</button>
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
<svg width="0" height="0" style="position:absolute" aria-hidden="true"><defs>
|
|
199
|
+
<radialGradient id="gP" cx=".35" cy=".25" r=".9"><stop offset="0" stop-color="#ffc0c7"/><stop offset=".38" stop-color="#ff3347"/><stop offset="1" stop-color="#b30d25"/></radialGradient>
|
|
200
|
+
<radialGradient id="gO" cx=".35" cy=".25" r=".9"><stop offset="0" stop-color="#ffb8c0"/><stop offset=".38" stop-color="#e8142f"/><stop offset="1" stop-color="#7d0a1c"/></radialGradient>
|
|
201
|
+
<radialGradient id="gL" cx=".35" cy=".25" r=".9"><stop offset="0" stop-color="#ffd0d5"/><stop offset=".38" stop-color="#ff5c70"/><stop offset="1" stop-color="#c11228"/></radialGradient>
|
|
202
|
+
</defs></svg>
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
<header class="pointer-events-none sticky top-0 z-40 pt-[calc(env(safe-area-inset-top)+0.75rem)]">
|
|
206
|
+
<div class="page-x mx-auto max-w-5xl">
|
|
207
|
+
<div class="topbar pointer-events-auto relative flex h-14 items-center gap-3 rounded-full pl-5 pr-2">
|
|
208
|
+
<a href="#" class="flex shrink-0 items-center gap-2.5" aria-label="mlv2 home">
|
|
209
|
+
<span class="orb"></span>
|
|
210
|
+
<span class="text-[17px] font-semibold tracking-[-0.02em]">mlv2</span>
|
|
211
|
+
</a>
|
|
212
|
+
<div role="search" class="ml-auto flex min-w-0 flex-1 items-center justify-end">
|
|
213
|
+
<div id="search-wrap" class="relative">
|
|
214
|
+
<svg class="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-ink-400" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><circle cx="11" cy="11" r="7"/><path d="m21 21-4.3-4.3"/></svg>
|
|
215
|
+
<input id="search" type="search" placeholder="Search games" aria-label="Search games" autocomplete="off" enterkeyhint="search" class="field rounded-full pl-9 pr-9" />
|
|
216
|
+
<button id="search-clear" type="button" aria-label="Clear search" class="absolute right-1.5 top-1/2 hidden h-7 w-7 -translate-y-1/2 place-items-center rounded-full text-ink-300 hover:text-white"><svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><path d="M18 6 6 18M6 6l12 12"/></svg></button>
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
<div class="flex shrink-0 items-center gap-1.5">
|
|
220
|
+
<button id="bell-btn" type="button" hidden aria-label="Announcements" class="glass-lite icon-btn relative">
|
|
221
|
+
<svg class="h-[18px] w-[18px]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"/><path d="M10.3 21a1.94 1.94 0 0 0 3.4 0"/></svg>
|
|
222
|
+
<span id="bell-dot" hidden class="absolute right-2 top-2 h-2.5 w-2.5 rounded-full bg-red-500 ring-2 ring-[#111113]"></span>
|
|
223
|
+
</button>
|
|
224
|
+
<button id="settings-btn" type="button" aria-label="Settings" aria-haspopup="dialog" class="glass-lite icon-btn">
|
|
225
|
+
<svg class="h-[18px] w-[18px]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></svg>
|
|
226
|
+
</button>
|
|
227
|
+
</div>
|
|
228
|
+
</div>
|
|
229
|
+
</div>
|
|
230
|
+
</header>
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
<main class="page-x relative z-10 mx-auto max-w-5xl pb-24">
|
|
234
|
+
|
|
235
|
+
<section class="relative pb-10 pt-12 sm:pb-14 sm:pt-20">
|
|
236
|
+
<div class="rise mb-5"><span id="count-badge" class="badge"><svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2l2.4 6.6L21 11l-6.6 2.4L12 20l-2.4-6.6L3 11l6.6-2.4z"/></svg><span><span id="count-num">0</span> games</span></span></div>
|
|
237
|
+
<h1 class="text-balance text-[2.75rem] font-semibold leading-[1.04] tracking-[-0.04em] text-ink-50 sm:text-[4.5rem]"><span class="w">school</span> <span class="w">sucks,</span><br/><span class="glowwrap"><span class="w glow-line">games</span> <span class="w glow-line">r</span> <span class="w glow-line">better</span></span></h1>
|
|
238
|
+
<p class="rise mt-4 text-[19px] text-ink-300 sm:text-[21px]" style="--d: 0.6s">we're so back</p>
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
<div id="shapes" class="pointer-events-none absolute right-2 top-4 hidden h-[360px] w-[400px] lg:block" aria-hidden="true">
|
|
242
|
+
<div class="shape" style="left:30px;top:90px;width:200px"><div class="par" data-depth="1"><svg viewBox="0 0 120 120" class="float" style="--r:-8deg;--g:rgba(240,26,54,.4);--d:-1s">
|
|
243
|
+
<rect x="8" y="30" width="104" height="62" rx="31" fill="url(#gP)"/>
|
|
244
|
+
<path d="M34 50v24M22 62h24" stroke="#fff" stroke-width="9" stroke-linecap="round" opacity=".92"/>
|
|
245
|
+
<circle cx="82" cy="54" r="6" fill="#fff" opacity=".92"/><circle cx="96" cy="68" r="6" fill="#fff" opacity=".92"/>
|
|
246
|
+
<ellipse cx="44" cy="40" rx="28" ry="7" fill="#fff" opacity=".45"/>
|
|
247
|
+
</svg></div></div>
|
|
248
|
+
<div class="shape" style="left:255px;top:10px;width:120px"><div class="par" data-depth="1.6"><svg viewBox="0 0 120 120" class="float" style="--r:10deg;--g:rgba(240,26,54,.35);--d:-3s">
|
|
249
|
+
<polygon points="60,16 71.8,43.8 101.9,46.4 79,66.2 85.9,95.6 60,80 34.1,95.6 41,66.2 18.2,46.4 48.2,43.8" fill="url(#gO)" stroke="url(#gO)" stroke-width="14" stroke-linejoin="round"/>
|
|
250
|
+
<ellipse cx="48" cy="40" rx="14" ry="5" fill="#fff" opacity=".5" transform="rotate(-25 48 40)"/>
|
|
251
|
+
</svg></div></div>
|
|
252
|
+
<div class="shape" style="left:255px;top:175px;width:105px"><div class="par" data-depth="0.8"><svg viewBox="0 0 120 120" class="float" style="--r:-6deg;--g:rgba(240,26,54,.35);--d:-2s">
|
|
253
|
+
<path d="M44 34 L90 60 L44 86 Z" fill="url(#gL)" stroke="url(#gL)" stroke-width="16" stroke-linejoin="round"/>
|
|
254
|
+
<ellipse cx="50" cy="48" rx="8" ry="4" fill="#fff" opacity=".55" transform="rotate(35 50 48)"/>
|
|
255
|
+
</svg></div></div>
|
|
256
|
+
<div class="shape" style="left:55px;top:268px;width:84px"><div class="par" data-depth="1.3"><svg viewBox="0 0 120 120" class="float" style="--r:8deg;--g:rgba(240,26,54,.3);--d:-4s">
|
|
257
|
+
<path d="M60 26v68M26 60h68" fill="none" stroke="url(#gP)" stroke-width="30" stroke-linecap="round"/>
|
|
258
|
+
<ellipse cx="52" cy="30" rx="6" ry="3" fill="#fff" opacity=".55"/>
|
|
259
|
+
</svg></div></div>
|
|
260
|
+
<div class="shape" style="left:165px;top:14px;width:52px"><div class="par" data-depth="2"><svg viewBox="0 0 120 120" class="float" style="--r:0deg;--g:rgba(240,26,54,.35);--d:-5s">
|
|
261
|
+
<circle cx="60" cy="60" r="42" fill="url(#gP)"/><ellipse cx="46" cy="42" rx="16" ry="8" fill="#fff" opacity=".55" transform="rotate(-30 46 42)"/>
|
|
262
|
+
</svg></div></div>
|
|
263
|
+
<div class="shape" style="left:175px;top:300px;width:40px"><div class="par" data-depth="1.8"><svg viewBox="0 0 120 120" class="float" style="--r:0deg;--g:rgba(240,26,54,.3);--d:-2.5s">
|
|
264
|
+
<circle cx="60" cy="60" r="42" fill="url(#gL)"/><ellipse cx="46" cy="42" rx="16" ry="8" fill="#fff" opacity=".55" transform="rotate(-30 46 42)"/>
|
|
265
|
+
</svg></div></div>
|
|
266
|
+
</div>
|
|
267
|
+
</section>
|
|
268
|
+
|
|
269
|
+
<div id="category-bar" role="group" aria-label="Categories" class="no-scrollbar -mx-5 -mt-2 mb-6 flex items-center gap-2 overflow-x-auto px-5 py-3 sm:mx-0 sm:mb-8 sm:px-0"></div>
|
|
270
|
+
|
|
271
|
+
<div id="setup-banner" class="glass-lite mb-8 hidden rounded-2xl p-4">
|
|
272
|
+
<p class="text-[15px] font-semibold">Not connected yet</p>
|
|
273
|
+
<p class="mt-1 text-[14px] leading-relaxed text-ink-300">Open this file and fill in the <code class="font-mono text-ink-50">CONFIG</code> object near the bottom with your Supabase project URL and anon key (Dashboard → Settings → API), then run <code class="font-mono text-ink-50">supabase-setup.sql</code> once.</p>
|
|
274
|
+
</div>
|
|
275
|
+
|
|
276
|
+
<h2 id="games-heading" tabindex="-1" class="sr-only">Games</h2>
|
|
277
|
+
<p id="grid-status" role="status" class="sr-only"></p>
|
|
278
|
+
<div id="skeleton-grid" class="grid grid-cols-3 gap-3 sm:grid-cols-4 sm:gap-4 md:grid-cols-5 lg:grid-cols-6"></div>
|
|
279
|
+
|
|
280
|
+
<div id="empty-state" aria-live="polite" class="hidden flex-col items-center justify-center py-24 text-center">
|
|
281
|
+
<p id="empty-title" class="text-[19px] font-semibold">No games yet</p>
|
|
282
|
+
<p id="empty-sub" class="mt-2 max-w-xs text-pretty text-[15px] text-ink-300">Games you add in the admin panel with a valid link will show up here automatically.</p>
|
|
283
|
+
<button id="retry" type="button" class="btn btn-ghost mt-5 hidden">Try again</button>
|
|
284
|
+
</div>
|
|
285
|
+
|
|
286
|
+
<div id="grid" class="hidden grid grid-cols-3 gap-3 sm:grid-cols-4 sm:gap-4 md:grid-cols-5 lg:grid-cols-6"></div>
|
|
287
|
+
</main>
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
<footer class="relative z-10 border-t border-white/[0.08]">
|
|
291
|
+
<div class="page-x mx-auto flex max-w-5xl items-center justify-between py-4 text-[13px] text-ink-400">
|
|
292
|
+
<p>mlv2 © <span id="year"></span></p>
|
|
293
|
+
<button id="admin-trigger" aria-haspopup="dialog" class="glass-lite rounded-full px-4 py-2 transition-colors duration-200 hover:text-ink-50">Admin</button>
|
|
294
|
+
</div>
|
|
295
|
+
</footer>
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
<div id="player-modal" class="fixed inset-0 z-50 hidden">
|
|
299
|
+
<div class="absolute inset-0 bg-black" data-player-close></div>
|
|
300
|
+
<div id="player-panel" role="dialog" aria-modal="true" aria-labelledby="player-title" class="relative flex h-full w-full flex-col opacity-0">
|
|
301
|
+
<div class="border-b border-white/[0.08] bg-black pt-[env(safe-area-inset-top)]">
|
|
302
|
+
<div class="flex h-14 items-center justify-between gap-3 px-3 sm:px-4">
|
|
303
|
+
<div class="flex min-w-0 items-center gap-3">
|
|
304
|
+
<img id="player-icon" class="h-8 w-8 rounded-[22.37%] object-cover" alt="" />
|
|
305
|
+
<p id="player-title" class="truncate text-[15px] font-semibold"></p>
|
|
306
|
+
</div>
|
|
307
|
+
<div class="flex shrink-0 items-center gap-2">
|
|
308
|
+
<button id="player-panic" type="button" hidden aria-label="Panic: leave this page now" title="Panic: leave this page now" class="glass-lite icon-btn">
|
|
309
|
+
<svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><path d="m16 17 5-5-5-5"/><path d="M21 12H9"/></svg>
|
|
310
|
+
</button>
|
|
311
|
+
<button id="player-fs" type="button" title="Fullscreen" aria-label="Fullscreen" class="glass-lite icon-btn">
|
|
312
|
+
<svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3H5a2 2 0 0 0-2 2v3M16 3h3a2 2 0 0 1 2 2v3M8 21H5a2 2 0 0 1-2-2v-3M16 21h3a2 2 0 0 0 2-2v-3"/></svg>
|
|
313
|
+
</button>
|
|
314
|
+
<a id="player-newtab" target="_blank" rel="noopener" title="Open in new tab" aria-label="Open in new tab" class="glass-lite icon-btn">
|
|
315
|
+
<svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><path d="M15 3h6v6"/><path d="M10 14 21 3"/></svg>
|
|
316
|
+
</a>
|
|
317
|
+
<button id="player-close" title="Close" aria-label="Close" class="glass-lite icon-btn">
|
|
318
|
+
<svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M18 6 6 18M6 6l12 12"/></svg>
|
|
319
|
+
</button>
|
|
320
|
+
</div>
|
|
321
|
+
</div>
|
|
322
|
+
</div>
|
|
323
|
+
<div class="relative flex-1 bg-black">
|
|
324
|
+
<div id="player-loading" class="absolute inset-0 grid place-items-center"><span class="orb pulse-orb" style="width:22px;height:22px"></span></div>
|
|
325
|
+
<iframe id="player-frame" class="relative h-full w-full" allow="autoplay; fullscreen; gamepad; pointer-lock; cross-origin-isolated" allowfullscreen loading="eager"></iframe>
|
|
326
|
+
</div>
|
|
327
|
+
</div>
|
|
328
|
+
</div>
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
<div id="admin-login-modal" data-nomask class="fixed inset-0 z-50 hidden">
|
|
332
|
+
<div data-backdrop="login" class="absolute inset-0 bg-black/50 backdrop-blur-md"></div>
|
|
333
|
+
<div class="pointer-events-none absolute inset-0 flex items-center justify-center p-4">
|
|
334
|
+
<form id="admin-login-form" role="dialog" aria-modal="true" aria-labelledby="pin-title" class="glass glass-sheet pointer-events-auto relative w-full max-w-[340px] rounded-[28px] p-6 opacity-0" data-fx>
|
|
335
|
+
<h2 id="pin-title" class="text-[19px] font-semibold">Enter PIN</h2>
|
|
336
|
+
<p class="mt-1.5 text-pretty text-[14px] text-ink-400">This unlocks the admin screen on this device. Write access is controlled by your Supabase row-level security policies.</p>
|
|
337
|
+
<div id="pin-boxes" role="group" aria-labelledby="pin-title" class="mt-5 grid grid-cols-6 gap-2"></div>
|
|
338
|
+
<input id="admin-pin" type="hidden" />
|
|
339
|
+
<p id="admin-login-error" class="mt-3 hidden text-[14px] text-red-400" role="alert"></p>
|
|
340
|
+
<button type="submit" id="admin-login-submit" class="btn btn-primary mt-5 w-full">Unlock</button>
|
|
341
|
+
<button type="button" data-admin-login-close class="btn btn-ghost mt-2 w-full">Cancel</button>
|
|
342
|
+
</form>
|
|
343
|
+
</div>
|
|
344
|
+
</div>
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
<div id="admin-panel" data-nomask class="fixed inset-0 z-50 hidden">
|
|
348
|
+
<div data-backdrop="admin" class="absolute inset-0 bg-black/50 backdrop-blur-md"></div>
|
|
349
|
+
<div class="pointer-events-none absolute inset-0 flex items-start justify-center p-0 sm:items-center sm:p-4">
|
|
350
|
+
<div id="admin-panel-card" role="dialog" aria-modal="true" aria-labelledby="admin-title" class="glass glass-sheet pointer-events-auto relative flex h-full w-full flex-col opacity-0 sm:h-[85vh] sm:max-w-2xl sm:rounded-[32px]">
|
|
351
|
+
<div class="flex shrink-0 items-center justify-between gap-3 px-5 pb-2 pt-[calc(env(safe-area-inset-top)+0.75rem)]">
|
|
352
|
+
<div class="min-w-0">
|
|
353
|
+
<h2 id="admin-title" tabindex="-1" class="text-[17px] font-semibold leading-tight">Admin</h2>
|
|
354
|
+
<p id="admin-summary" class="mt-0.5 text-[13px] text-ink-300"></p>
|
|
355
|
+
</div>
|
|
356
|
+
<div class="flex shrink-0 items-center gap-2">
|
|
357
|
+
<button id="admin-logout" type="button" class="btn btn-ghost">Lock</button>
|
|
358
|
+
<button id="admin-close" type="button" aria-label="Close" class="glass-lite icon-btn"><svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M18 6 6 18M6 6l12 12"/></svg></button>
|
|
359
|
+
</div>
|
|
360
|
+
</div>
|
|
361
|
+
<div id="admin-tabs" role="tablist" aria-label="Admin sections" class="flex shrink-0 gap-1 border-b border-white/[0.08] px-5 pb-3">
|
|
362
|
+
<button id="atab-games" role="tab" type="button" aria-selected="true" aria-controls="admin-tab-games" data-atab="games" class="tab">Games</button>
|
|
363
|
+
<button id="atab-ann" role="tab" type="button" aria-selected="false" tabindex="-1" aria-controls="admin-tab-ann" data-atab="ann" class="tab">Announcements</button>
|
|
364
|
+
</div>
|
|
365
|
+
|
|
366
|
+
<div id="admin-tab-games" role="tabpanel" aria-labelledby="atab-games" class="flex min-h-0 flex-1 flex-col">
|
|
367
|
+
<div class="flex shrink-0 gap-2 px-5 pt-4">
|
|
368
|
+
<div class="min-w-0 flex-1">
|
|
369
|
+
<label for="admin-filter" class="sr-only">Filter games</label>
|
|
370
|
+
<input id="admin-filter" type="search" placeholder="Filter games" autocomplete="off" class="field" />
|
|
371
|
+
</div>
|
|
372
|
+
<button id="admin-add" type="button" class="btn btn-primary shrink-0">Add game</button>
|
|
373
|
+
</div>
|
|
374
|
+
<div id="admin-body" class="min-h-0 flex-1 overflow-y-auto px-5 py-4">
|
|
375
|
+
<div id="admin-form-slot"></div>
|
|
376
|
+
<ul id="admin-list" class="space-y-2" aria-label="Games"></ul>
|
|
377
|
+
</div>
|
|
378
|
+
</div>
|
|
379
|
+
|
|
380
|
+
<div id="admin-tab-ann" role="tabpanel" aria-labelledby="atab-ann" hidden class="flex min-h-0 flex-1 flex-col">
|
|
381
|
+
<div class="flex shrink-0 items-center justify-between gap-3 px-5 pt-4">
|
|
382
|
+
<p class="text-[13px] text-ink-300">Shown to visitors when they open the site.</p>
|
|
383
|
+
<button id="ann-add" type="button" class="btn btn-primary shrink-0">New announcement</button>
|
|
384
|
+
</div>
|
|
385
|
+
<div id="ann-admin-body" class="min-h-0 flex-1 overflow-y-auto px-5 py-4">
|
|
386
|
+
<div id="ann-form-slot"></div>
|
|
387
|
+
<ul id="ann-admin-list" class="space-y-2" aria-label="Announcements"></ul>
|
|
388
|
+
</div>
|
|
389
|
+
</div>
|
|
390
|
+
<p id="admin-live" role="status" class="sr-only"></p>
|
|
391
|
+
</div>
|
|
392
|
+
</div>
|
|
393
|
+
</div>
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
<div id="ann-modal" class="fixed inset-0 z-50 hidden">
|
|
397
|
+
<div data-backdrop="ann" class="absolute inset-0 bg-black/50 backdrop-blur-md"></div>
|
|
398
|
+
<div class="pointer-events-none absolute inset-0 flex items-center justify-center p-4">
|
|
399
|
+
<div id="ann-card" role="dialog" aria-modal="true" aria-labelledby="ann-title" class="glass glass-sheet pointer-events-auto relative flex max-h-[85vh] w-full max-w-[480px] flex-col rounded-[32px] opacity-0">
|
|
400
|
+
<div class="flex shrink-0 items-center justify-between gap-3 px-6 pb-1 pt-5">
|
|
401
|
+
<h2 id="ann-title" tabindex="-1" class="text-[19px] font-semibold">Announcements</h2>
|
|
402
|
+
<button id="ann-close" type="button" aria-label="Close" class="glass-lite icon-btn"><svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M18 6 6 18M6 6l12 12"/></svg></button>
|
|
403
|
+
</div>
|
|
404
|
+
<div id="ann-list" class="min-h-0 flex-1 space-y-3 overflow-y-auto px-4 pb-2 pt-3"></div>
|
|
405
|
+
<div class="shrink-0 px-4 pb-4 pt-2"><button id="ann-done" type="button" class="btn btn-primary w-full">Got it</button></div>
|
|
406
|
+
</div>
|
|
407
|
+
</div>
|
|
408
|
+
</div>
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
<div id="settings-modal" data-nomask class="fixed inset-0 z-50 hidden">
|
|
412
|
+
<div data-backdrop="settings" class="absolute inset-0 bg-black/50 backdrop-blur-md"></div>
|
|
413
|
+
<div class="pointer-events-none absolute inset-0 flex items-start justify-center p-0 sm:items-center sm:p-4">
|
|
414
|
+
<div id="settings-card" role="dialog" aria-modal="true" aria-labelledby="settings-title" class="glass glass-sheet pointer-events-auto relative flex h-full w-full flex-col opacity-0 sm:h-[82vh] sm:max-w-xl sm:rounded-[32px]">
|
|
415
|
+
<div class="flex shrink-0 items-center justify-between gap-3 px-5 pb-2 pt-[calc(env(safe-area-inset-top)+0.9rem)]">
|
|
416
|
+
<h2 id="settings-title" tabindex="-1" class="text-[19px] font-semibold">Settings</h2>
|
|
417
|
+
<button id="settings-close" type="button" aria-label="Close" class="glass-lite icon-btn"><svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M18 6 6 18M6 6l12 12"/></svg></button>
|
|
418
|
+
</div>
|
|
419
|
+
<div id="settings-tabs" role="tablist" aria-label="Settings sections" class="flex shrink-0 gap-1 px-5 pb-3">
|
|
420
|
+
<button id="stab-general" role="tab" type="button" aria-selected="true" aria-controls="spanel-general" class="tab">General</button>
|
|
421
|
+
<button id="stab-cloak" role="tab" type="button" aria-selected="false" tabindex="-1" aria-controls="spanel-cloak" class="tab">Cloak</button>
|
|
422
|
+
<button id="stab-data" role="tab" type="button" aria-selected="false" tabindex="-1" aria-controls="spanel-data" class="tab">Data</button>
|
|
423
|
+
</div>
|
|
424
|
+
<div class="min-h-0 flex-1 overflow-y-auto px-5 pb-8">
|
|
425
|
+
|
|
426
|
+
<section id="spanel-general" role="tabpanel" aria-labelledby="stab-general">
|
|
427
|
+
<h3 class="shead">Experience</h3>
|
|
428
|
+
<div class="sgroup">
|
|
429
|
+
<label class="srow"><span class="min-w-0"><span class="block text-[15px] font-medium">Show announcements when I open the site</span><span class="mt-0.5 block text-[13px] text-ink-300">You can always reopen them with the bell in the top bar.</span></span><input id="set-announce" type="checkbox" role="switch" class="switch" /></label>
|
|
430
|
+
<label class="srow"><span class="min-w-0"><span class="block text-[15px] font-medium">Reduce motion</span><span class="mt-0.5 block text-[13px] text-ink-300">Turns off animations. Already on if your device asks for it.</span></span><input id="set-reduce" type="checkbox" role="switch" class="switch" /></label>
|
|
431
|
+
<div class="srow plain"><span id="tile-label" class="text-[15px] font-medium">Tile size</span><div role="radiogroup" aria-labelledby="tile-label" class="flex shrink-0 gap-1"><label class="pill-opt"><input type="radio" name="tile" value="compact" class="sr-only" /><span>Compact</span></label><label class="pill-opt"><input type="radio" name="tile" value="default" class="sr-only" /><span>Default</span></label><label class="pill-opt"><input type="radio" name="tile" value="large" class="sr-only" /><span>Large</span></label></div></div>
|
|
432
|
+
</div>
|
|
433
|
+
<h3 class="shead">Admin</h3>
|
|
434
|
+
<div class="sgroup"><div class="srow plain"><span class="min-w-0"><span class="block text-[15px] font-medium">Admin panel</span><span class="mt-0.5 block text-[13px] text-ink-300">Add games, post announcements and change the order.</span></span><button id="open-admin" type="button" class="btn btn-ghost shrink-0">Open</button></div></div>
|
|
435
|
+
</section>
|
|
436
|
+
|
|
437
|
+
<section id="spanel-cloak" role="tabpanel" aria-labelledby="stab-cloak" hidden>
|
|
438
|
+
<h3 class="shead">Tab disguise</h3>
|
|
439
|
+
<p class="mb-3 px-1 text-[13px] text-ink-300">Changes the tab's title and icon so it looks like something else.</p>
|
|
440
|
+
<div id="cloak-options" role="radiogroup" aria-label="Tab disguise" class="grid gap-2"></div>
|
|
441
|
+
<div id="custom-cloak" hidden class="mt-3 space-y-3">
|
|
442
|
+
<div><label for="cc-title" class="text-[13px] font-medium text-ink-200">Tab title</label><input id="cc-title" maxlength="80" autocomplete="off" class="field mt-1.5" /></div>
|
|
443
|
+
<div><label for="cc-icon" class="text-[13px] font-medium text-ink-200">Icon link <span class="font-normal text-ink-300">(optional)</span></label><input id="cc-icon" type="url" inputmode="url" autocomplete="off" spellcheck="false" placeholder="https://" class="field mt-1.5" /></div>
|
|
444
|
+
</div>
|
|
445
|
+
|
|
446
|
+
<h3 class="shead">Panic button</h3>
|
|
447
|
+
<div class="sgroup">
|
|
448
|
+
<label class="srow"><span class="min-w-0"><span class="block text-[15px] font-medium">Enable panic button</span><span class="mt-0.5 block text-[13px] text-ink-300">Instantly leaves this page and opens the site below.</span></span><input id="panic-on" type="checkbox" role="switch" class="switch" /></label>
|
|
449
|
+
<div class="srow plain"><span class="min-w-0"><span class="block text-[15px] font-medium">Shortcut</span><span class="mt-0.5 block text-[13px] text-ink-300"><span id="panic-key-hint">Works while this page has focus, not inside a game.</span></span></span><button id="panic-key" type="button" aria-describedby="panic-key-hint" class="btn btn-ghost shrink-0"></button></div>
|
|
450
|
+
<div class="py-3.5"><label for="panic-url" class="block text-[15px] font-medium">Go to</label><input id="panic-url" type="url" inputmode="url" autocomplete="off" spellcheck="false" aria-describedby="panic-url-err" class="field mt-1.5" /><p id="panic-url-err" role="alert" class="mt-1.5 hidden text-[13px] text-red-300"></p></div>
|
|
451
|
+
<label class="srow"><span class="min-w-0"><span class="block text-[15px] font-medium">Show an on-screen button</span><span class="mt-0.5 block text-[13px] text-ink-300">A small button in the corner and in the game window, for phones or when a game has focus.</span></span><input id="panic-btn-on" type="checkbox" role="switch" class="switch" /></label>
|
|
452
|
+
</div>
|
|
453
|
+
|
|
454
|
+
<h3 class="shead">Privacy</h3>
|
|
455
|
+
<div class="sgroup">
|
|
456
|
+
<label class="srow"><span class="min-w-0"><span class="block text-[15px] font-medium">Mask text</span><span class="mt-0.5 block text-[13px] text-ink-300">Swaps letters for look-alike characters so on-screen keyword scanners can't read them. Screen readers may read masked text oddly.</span></span><input id="set-mask" type="checkbox" role="switch" class="switch" /></label>
|
|
457
|
+
<label class="srow"><span class="min-w-0"><span class="block text-[15px] font-medium">Ask before closing this tab</span><span class="mt-0.5 block text-[13px] text-ink-300">Shows your browser's “leave site?” prompt so you don't close it by accident.</span></span><input id="set-confirm" type="checkbox" role="switch" class="switch" /></label>
|
|
458
|
+
<div class="srow plain"><span class="min-w-0"><span class="block text-[15px] font-medium">Open in about:blank</span><span class="mt-0.5 block text-[13px] text-ink-300">Opens the site in a blank tab and sends this tab to your panic page.</span></span><button id="launch-blank" type="button" class="btn btn-ghost shrink-0">Open</button></div>
|
|
459
|
+
</div>
|
|
460
|
+
</section>
|
|
461
|
+
|
|
462
|
+
<section id="spanel-data" role="tabpanel" aria-labelledby="stab-data" hidden>
|
|
463
|
+
<h3 class="shead">Your settings</h3>
|
|
464
|
+
<div class="sgroup">
|
|
465
|
+
<div class="srow plain"><span class="min-w-0"><span class="block text-[15px] font-medium">Export settings</span><span class="mt-0.5 block text-[13px] text-ink-300">Save your settings to a file.</span></span><button id="export-settings" type="button" class="btn btn-ghost shrink-0">Export</button></div>
|
|
466
|
+
<div class="srow plain"><span class="min-w-0"><span class="block text-[15px] font-medium">Import settings</span><span class="mt-0.5 block text-[13px] text-ink-300">Load settings from a file you exported.</span></span><button id="import-settings-btn" type="button" class="btn btn-ghost shrink-0">Import</button><input id="import-settings" type="file" accept="application/json,.json" tabindex="-1" aria-label="Settings file" class="sr-only" /></div>
|
|
467
|
+
<div class="srow plain"><span class="min-w-0"><span class="block text-[15px] font-medium">Show announcements again</span><span class="mt-0.5 block text-[13px] text-ink-300">Forget which announcements you've already seen.</span></span><button id="reset-seen" type="button" class="btn btn-ghost shrink-0">Reset</button></div>
|
|
468
|
+
<div class="srow plain"><span class="min-w-0"><span class="block text-[15px] font-medium">Reset settings</span><span class="mt-0.5 block text-[13px] text-ink-300">Put every setting back to its default.</span></span><button id="reset-settings" type="button" class="btn btn-ghost shrink-0">Reset</button></div>
|
|
469
|
+
</div>
|
|
470
|
+
|
|
471
|
+
<h3 class="shead">Game library</h3>
|
|
472
|
+
<p id="lib-lock" class="mb-3 px-1 text-[13px] text-ink-300">Admin only. Unlock the admin panel to back up or restore your games.</p>
|
|
473
|
+
<div class="sgroup">
|
|
474
|
+
<div class="srow plain"><span class="min-w-0"><span class="block text-[15px] font-medium">Export games</span><span class="mt-0.5 block text-[13px] text-ink-300">Download every game as a file.</span></span><button id="export-games" type="button" class="btn btn-ghost shrink-0">Export</button></div>
|
|
475
|
+
<div class="srow plain"><span class="min-w-0"><span class="block text-[15px] font-medium">Import games</span><span class="mt-0.5 block text-[13px] text-ink-300">Add games from an export. Duplicates are skipped.</span></span><button id="import-games-btn" type="button" class="btn btn-ghost shrink-0">Choose file</button><input id="import-games" type="file" accept="application/json,.json" tabindex="-1" aria-label="Games file" class="sr-only" /></div>
|
|
476
|
+
</div>
|
|
477
|
+
<p id="lib-status" role="status" class="mt-3 px-1 text-[13px] text-ink-200"></p>
|
|
478
|
+
<div class="mt-3 flex gap-2"><button id="import-games-go" type="button" hidden class="btn btn-primary"></button><button id="unlock-admin" type="button" hidden class="btn btn-ghost">Unlock admin</button></div>
|
|
479
|
+
</section>
|
|
480
|
+
</div>
|
|
481
|
+
</div>
|
|
482
|
+
</div>
|
|
483
|
+
</div>
|
|
484
|
+
|
|
485
|
+
<div id="toast-root" role="status" aria-live="polite" class="pointer-events-none fixed inset-x-0 bottom-4 z-[60] flex flex-col items-center gap-2 px-4 pb-[env(safe-area-inset-bottom)]"></div>
|
|
486
|
+
|
|
487
|
+
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
|
|
488
|
+
<script type="module">
|
|
489
|
+
import { animate, stagger, inView } from "https://cdn.jsdelivr.net/npm/motion@12/+esm";
|
|
490
|
+
|
|
491
|
+
const CONFIG = JSON.parse(atob("eyJzdXBhYmFzZVVybCI6Imh0dHBzOi8vdnphb2ViYXVpZmFmbmZmYmZpeG8uc3VwYWJhc2UuY28iLCJzdXBhYmFzZUFub25LZXkiOiJleUpoYkdjaU9pSklVekkxTmlJc0luUjVjQ0k2SWtwWFZDSjkuZXlKcGMzTWlPaUp6ZFhCaFltRnpaU0lzSW5KbFppSTZJblo2WVc5bFltRjFhV1poWm01bVptSm1hWGh2SWl3aWNtOXNaU0k2SW1GdWIyNGlMQ0pwWVhRaU9qRTNPVEkzT1Rjd05EY3NJbVY0Y0NJNk1qRXdPRE0zTXpBME4zMC45UFlFZjVPQ3lEckR2LVhSTzJ2OGM4SThwVDN0UDEydFVDQlZ3a3NoU0dZIiwiZ2FtZXNUYWJsZSI6ImdhbWVzIiwiYW5ub3VuY2VtZW50c1RhYmxlIjoiYW5ub3VuY2VtZW50cyIsImljb25zQnVja2V0IjoiZ2FtZS1pY29ucyJ9"));
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
// The admin PIN is stored only as its SHA-256 hash, so the raw PIN never appears in this file
|
|
495
|
+
// (and therefore never appears in anything published from it).
|
|
496
|
+
// To change the PIN run: node distribute.mjs pin "your-new-pin"
|
|
497
|
+
const ADMIN_PIN_HASH = "331d503c76c92a3e12f263b1d8cca20a1e7ee581cabe58f356806c299865cac1";
|
|
498
|
+
const ADMIN_SESSION_KEY = "mlv2_admin_unlocked";
|
|
499
|
+
|
|
500
|
+
// sha256Hex: small self-contained SHA-256 (works in any context, no crypto.subtle needed).
|
|
501
|
+
// Verified against Node's crypto on empty/short/multi-block/unicode inputs.
|
|
502
|
+
function sha256Hex(str) {
|
|
503
|
+
const K = [0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,
|
|
504
|
+
0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,
|
|
505
|
+
0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,
|
|
506
|
+
0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,
|
|
507
|
+
0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,
|
|
508
|
+
0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,
|
|
509
|
+
0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,
|
|
510
|
+
0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2];
|
|
511
|
+
const rotr = (x, n) => (x >>> n) | (x << (32 - n));
|
|
512
|
+
const bytes = new TextEncoder().encode(str);
|
|
513
|
+
const bitLen = bytes.length * 8;
|
|
514
|
+
const blocks = Math.ceil((bytes.length + 9) / 64);
|
|
515
|
+
const buf = new Uint8Array(blocks * 64);
|
|
516
|
+
buf.set(bytes);
|
|
517
|
+
buf[bytes.length] = 0x80;
|
|
518
|
+
const view = new DataView(buf.buffer);
|
|
519
|
+
view.setUint32(buf.length - 8, Math.floor(bitLen / 0x100000000));
|
|
520
|
+
view.setUint32(buf.length - 4, bitLen >>> 0);
|
|
521
|
+
let h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372, h3 = 0xa54ff53a,
|
|
522
|
+
h4 = 0x510e527f, h5 = 0x9b05688c, h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
|
|
523
|
+
const w = new Uint32Array(64);
|
|
524
|
+
for (let b = 0; b < blocks; b++) {
|
|
525
|
+
for (let i = 0; i < 16; i++) w[i] = view.getUint32(b * 64 + i * 4);
|
|
526
|
+
for (let i = 16; i < 64; i++) {
|
|
527
|
+
const x = w[i - 15], y = w[i - 2];
|
|
528
|
+
const s0 = rotr(x, 7) ^ rotr(x, 18) ^ (x >>> 3);
|
|
529
|
+
const s1 = rotr(y, 17) ^ rotr(y, 19) ^ (y >>> 10);
|
|
530
|
+
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) | 0;
|
|
531
|
+
}
|
|
532
|
+
let a = h0, bb = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7;
|
|
533
|
+
for (let i = 0; i < 64; i++) {
|
|
534
|
+
const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
535
|
+
const ch = (e & f) ^ (~e & g);
|
|
536
|
+
const t1 = (h + S1 + ch + K[i] + w[i]) | 0;
|
|
537
|
+
const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
538
|
+
const maj = (a & bb) ^ (a & c) ^ (bb & c);
|
|
539
|
+
const t2 = (S0 + maj) | 0;
|
|
540
|
+
h = g; g = f; f = e; e = (d + t1) | 0; d = c; c = bb; bb = a; a = (t1 + t2) | 0;
|
|
541
|
+
}
|
|
542
|
+
h0 = (h0 + a) | 0; h1 = (h1 + bb) | 0; h2 = (h2 + c) | 0; h3 = (h3 + d) | 0;
|
|
543
|
+
h4 = (h4 + e) | 0; h5 = (h5 + f) | 0; h6 = (h6 + g) | 0; h7 = (h7 + h) | 0;
|
|
544
|
+
}
|
|
545
|
+
return [h0, h1, h2, h3, h4, h5, h6, h7].map((x) => (x >>> 0).toString(16).padStart(8, "0")).join("");
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// supabase-js returns { data, error } instead of throwing. Turn errors into real exceptions
|
|
549
|
+
// so every existing try/catch + error toast keeps working unchanged.
|
|
550
|
+
const unwrap = (p) => p.then(({ data, error }) => { if (error) throw new Error(error.message); return data; });
|
|
551
|
+
|
|
552
|
+
let sb = null;
|
|
553
|
+
try { sb = window.supabase.createClient(CONFIG.supabaseUrl, CONFIG.supabaseAnonKey); }
|
|
554
|
+
catch { /* invalid CONFIG — the setup banner takes over until it's filled in */ }
|
|
555
|
+
|
|
556
|
+
const isConfigured = () =>
|
|
557
|
+
!CONFIG.supabaseUrl.includes("YOUR_") && !CONFIG.supabaseAnonKey.includes("YOUR_");
|
|
558
|
+
|
|
559
|
+
/* ------------------------------ settings model ------------------------------ */
|
|
560
|
+
const SETTINGS_KEY = "mlv2_settings";
|
|
561
|
+
const isHttp = (v) => { try { const p = new URL(v).protocol; return p === "http:" || p === "https:"; } catch { return false; } };
|
|
562
|
+
const ico = (svg) => "data:image/svg+xml," + encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">${svg}</svg>`);
|
|
563
|
+
const SIZES = {
|
|
564
|
+
compact: "grid-cols-4 sm:grid-cols-6 md:grid-cols-7 lg:grid-cols-8",
|
|
565
|
+
default: "grid-cols-3 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6",
|
|
566
|
+
large: "grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5",
|
|
567
|
+
};
|
|
568
|
+
const CLOAKS = {
|
|
569
|
+
off: { label: "Off", sub: "Show the normal mlv2 tab", title: null, icon: null },
|
|
570
|
+
classroom: { label: "Google Classroom", sub: "Tab reads “Classes”", title: "Classes",
|
|
571
|
+
icon: ico('<rect width="32" height="32" rx="7" fill="#1e8e3e"/><rect x="6" y="9" width="20" height="14" rx="2" fill="#fff"/><circle cx="16" cy="16" r="3" fill="#1e8e3e"/><path d="M10 26h12" stroke="#fff" stroke-width="2" stroke-linecap="round"/>') },
|
|
572
|
+
ixl: { label: "IXL", sub: "Tab reads “IXL | Math, Language Arts, Science…”", title: "IXL | Math, Language Arts, Science, Social Studies, and Spanish",
|
|
573
|
+
icon: ico('<rect width="32" height="32" rx="7" fill="#fff"/><text x="16" y="21" font-family="Arial,sans-serif" font-size="12" font-weight="800" text-anchor="middle" fill="#0a74da">IXL</text>') },
|
|
574
|
+
github: { label: "GitHub", sub: "Tab reads “GitHub”", title: "GitHub",
|
|
575
|
+
icon: ico('<rect width="32" height="32" rx="16" fill="#0d1117"/><g transform="translate(4 4) scale(1.5)"><path fill="#fff" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></g>') },
|
|
576
|
+
blank: { label: "Blank", sub: "No visible title or icon", title: "\u00A0", icon: ico("") },
|
|
577
|
+
custom: { label: "Custom", sub: "Pick your own title and icon", title: null, icon: null },
|
|
578
|
+
};
|
|
579
|
+
const DEFAULTS = {
|
|
580
|
+
announceOnOpen: true, reduceMotion: false, tileSize: "default",
|
|
581
|
+
cloak: "off", customTitle: "", customIcon: "", maskText: false, confirmClose: false,
|
|
582
|
+
panic: { enabled: false, key: "`", url: "https://classroom.google.com", button: false },
|
|
583
|
+
};
|
|
584
|
+
function mergeSettings(base, src) {
|
|
585
|
+
const out = JSON.parse(JSON.stringify(base));
|
|
586
|
+
if (!src || typeof src !== "object") return out;
|
|
587
|
+
for (const k of Object.keys(base)) {
|
|
588
|
+
if (k === "panic") {
|
|
589
|
+
const p = src.panic && typeof src.panic === "object" ? src.panic : {};
|
|
590
|
+
for (const pk of Object.keys(base.panic)) if (typeof p[pk] === typeof base.panic[pk]) out.panic[pk] = p[pk];
|
|
591
|
+
} else if (typeof src[k] === typeof base[k]) out[k] = src[k];
|
|
592
|
+
}
|
|
593
|
+
if (!CLOAKS[out.cloak]) out.cloak = "off";
|
|
594
|
+
if (!SIZES[out.tileSize]) out.tileSize = "default";
|
|
595
|
+
if (!out.panic.key) out.panic.key = DEFAULTS.panic.key;
|
|
596
|
+
return out;
|
|
597
|
+
}
|
|
598
|
+
function loadSettings() { try { return mergeSettings(DEFAULTS, JSON.parse(localStorage.getItem(SETTINGS_KEY))); } catch { return mergeSettings(DEFAULTS, null); } }
|
|
599
|
+
function saveSettings() { try { localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings)); } catch { /* storage blocked */ } }
|
|
600
|
+
let settings = loadSettings();
|
|
601
|
+
const sysReduce = matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
602
|
+
let reduceMotion = sysReduce || settings.reduceMotion;
|
|
603
|
+
|
|
604
|
+
function fx(targets, keyframes, options = {}) {
|
|
605
|
+
if (reduceMotion) options = { ...options, duration: 0, delay: 0 };
|
|
606
|
+
return animate(targets, keyframes, options);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function pop(targets, { y = 12, scale = 0.94, delay = 0, stiff = 320, damp = 24 } = {}) {
|
|
610
|
+
if (reduceMotion) return animate(targets, { opacity: 1 }, { duration: 0 });
|
|
611
|
+
animate(targets, { opacity: [0, 1] }, { duration: 0.35, delay, ease: "easeOut" });
|
|
612
|
+
return animate(targets, { y: [y, 0], scale: [scale, 1] }, { type: "spring", stiffness: stiff, damping: damp, delay });
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/* ------------------------------- state ------------------------------- */
|
|
616
|
+
let allGames = [];
|
|
617
|
+
let activeCategory = "All";
|
|
618
|
+
let searchTerm = "";
|
|
619
|
+
const BRAND = "#f01a36";
|
|
620
|
+
const PALETTE = ["#f01a36"];
|
|
621
|
+
let catColors = {};
|
|
622
|
+
let barShown = false;
|
|
623
|
+
|
|
624
|
+
const el = (id) => document.getElementById(id);
|
|
625
|
+
document.getElementById("year").textContent = new Date().getFullYear();
|
|
626
|
+
|
|
627
|
+
/* ------------------------------ helpers ------------------------------ */
|
|
628
|
+
function iconSrcFor(row) {
|
|
629
|
+
if (row.icon_file_id) return `${CONFIG.supabaseUrl}/storage/v1/object/public/${CONFIG.iconsBucket}/${row.icon_file_id}`;
|
|
630
|
+
if (row.icon_url) return row.icon_url;
|
|
631
|
+
return null;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
function monogramSrc(name) {
|
|
635
|
+
const initials = (name || "?").trim().slice(0, 2).toUpperCase();
|
|
636
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
|
|
637
|
+
<rect width="100" height="100" fill="#161618"/>
|
|
638
|
+
<text x="50" y="58" font-family="-apple-system, Inter, sans-serif" font-size="34" font-weight="600" fill="#f01a36" text-anchor="middle">${initials}</text>
|
|
639
|
+
</svg>`;
|
|
640
|
+
return "data:image/svg+xml;utf8," + encodeURIComponent(svg);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function escapeHtml(s) {
|
|
644
|
+
return String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]));
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
function toast(message, tone = "default") {
|
|
648
|
+
const root = el("toast-root");
|
|
649
|
+
const node = document.createElement("div");
|
|
650
|
+
const toneClasses = tone === "error" ? "text-red-300" : "text-ink-50";
|
|
651
|
+
node.className = `glass glass-sheet pointer-events-auto relative rounded-full ${toneClasses} px-4 py-2.5 text-[14px] opacity-0`;
|
|
652
|
+
node.textContent = message;
|
|
653
|
+
root.appendChild(node);
|
|
654
|
+
pop(node, { y: 16, scale: 0.9, stiff: 420, damp: 24 });
|
|
655
|
+
setTimeout(() => {
|
|
656
|
+
fx(node, { opacity: [1, 0], y: [0, 6] }, { duration: 0.2, ease: "easeIn" }).finished.then(() => node.remove());
|
|
657
|
+
}, 2800);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/* -------------------------- render: skeleton -------------------------- */
|
|
661
|
+
function renderSkeleton() {
|
|
662
|
+
el("skeleton-grid").innerHTML = Array.from({ length: 12 })
|
|
663
|
+
.map(() => `<div class="glass-lite rounded-[28px] p-2.5"><div class="shimmer aspect-square rounded-[22.37%]"></div><div class="shimmer mx-auto mt-3 h-3 w-2/3 rounded-full"></div></div>`)
|
|
664
|
+
.join("");
|
|
665
|
+
}
|
|
666
|
+
renderSkeleton();
|
|
667
|
+
|
|
668
|
+
/* ---------------------------- render: grid ---------------------------- */
|
|
669
|
+
function currentFiltered() {
|
|
670
|
+
return allGames.filter((g) => {
|
|
671
|
+
const matchesCategory = activeCategory === "All" || (g.category || "Uncategorized") === activeCategory;
|
|
672
|
+
const matchesSearch = !searchTerm || g.name.toLowerCase().includes(searchTerm);
|
|
673
|
+
return matchesCategory && matchesSearch;
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
function renderCategoryBar(mode) {
|
|
678
|
+
const names = [...new Set(allGames.map((g) => g.category || "Uncategorized"))];
|
|
679
|
+
catColors = {};
|
|
680
|
+
names.forEach((n, i) => (catColors[n] = PALETTE[i % PALETTE.length]));
|
|
681
|
+
const countOf = (n) => allGames.filter((g) => (g.category || "Uncategorized") === n).length;
|
|
682
|
+
const bar = el("category-bar");
|
|
683
|
+
bar.innerHTML = ["All", ...names]
|
|
684
|
+
.map((c) => {
|
|
685
|
+
const active = c === activeCategory;
|
|
686
|
+
const color = c === "All" ? BRAND : catColors[c];
|
|
687
|
+
const n = c === "All" ? allGames.length : countOf(c);
|
|
688
|
+
return `<button data-cat="${escapeHtml(c)}" aria-pressed="${active}" style="--c:${color}" class="chip ${mode === "intro" ? "opacity-0 " : ""}${
|
|
689
|
+
active ? "chip-on text-white" : "glass-lite text-ink-200 hover:text-ink-50"
|
|
690
|
+
}">${escapeHtml(c)}<span class="chip-count">${n}</span></button>`;
|
|
691
|
+
})
|
|
692
|
+
.join("");
|
|
693
|
+
bar.querySelectorAll("[data-cat]").forEach((btn) =>
|
|
694
|
+
btn.addEventListener("click", () => {
|
|
695
|
+
activeCategory = btn.dataset.cat;
|
|
696
|
+
renderCategoryBar("click");
|
|
697
|
+
renderGrid();
|
|
698
|
+
})
|
|
699
|
+
);
|
|
700
|
+
if (mode === "intro") pop("#category-bar .chip", { y: 10, scale: 0.9, delay: stagger(0.05, { startDelay: 0.3 }), stiff: 380, damp: 22 });
|
|
701
|
+
if (mode === "click" && !reduceMotion) {
|
|
702
|
+
const on = bar.querySelector('[aria-pressed="true"]');
|
|
703
|
+
if (on) animate(on, { scale: [0.88, 1] }, { type: "spring", stiffness: 520, damping: 16 });
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
let gridShown = false;
|
|
708
|
+
function renderGrid() {
|
|
709
|
+
const grid = el("grid");
|
|
710
|
+
const games = currentFiltered();
|
|
711
|
+
el("grid-status").textContent = allGames.length === 0 ? "No games yet" : games.length === 0 ? "No games match your search" : `${games.length} ${games.length === 1 ? "game" : "games"} shown`;
|
|
712
|
+
el("skeleton-grid").classList.add("hidden");
|
|
713
|
+
|
|
714
|
+
if (allGames.length === 0) {
|
|
715
|
+
grid.classList.add("hidden");
|
|
716
|
+
el("empty-state").classList.remove("hidden");
|
|
717
|
+
el("empty-state").classList.add("flex");
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
if (games.length === 0) {
|
|
721
|
+
grid.classList.add("hidden");
|
|
722
|
+
el("empty-title").textContent = "Nothing matches";
|
|
723
|
+
el("empty-sub").textContent = "Try a different search term or category.";
|
|
724
|
+
el("empty-state").classList.remove("hidden");
|
|
725
|
+
el("empty-state").classList.add("flex");
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
el("empty-state").classList.add("hidden");
|
|
730
|
+
el("empty-state").classList.remove("flex");
|
|
731
|
+
grid.classList.remove("hidden");
|
|
732
|
+
|
|
733
|
+
grid.innerHTML = games
|
|
734
|
+
.map((g) => {
|
|
735
|
+
const src = iconSrcFor(g) || monogramSrc(g.name);
|
|
736
|
+
const color = catColors[g.category || "Uncategorized"] || BRAND;
|
|
737
|
+
return `<button data-fx data-id="${g.id}" style="--c:${color}" class="tile group block w-full text-left opacity-0">
|
|
738
|
+
<span class="tile-icon block aspect-square overflow-hidden rounded-[22.37%] bg-ink-800 transition-transform duration-300 ease-out group-hover:scale-[1.05] group-active:scale-[0.97]">
|
|
739
|
+
<img src="${src}" alt="" loading="lazy" class="tile-img h-full w-full object-cover" onerror="this.onerror=null;this.src='${monogramSrc(g.name)}'" />
|
|
740
|
+
</span>
|
|
741
|
+
<span class="mt-3 block truncate text-center text-[13px] font-medium leading-tight text-ink-50">${escapeHtml(g.name)}</span>
|
|
742
|
+
${g.category ? `<span class="mt-0.5 block truncate text-center text-[12px] text-ink-400">${escapeHtml(g.category)}</span>` : ""}
|
|
743
|
+
</button>`;
|
|
744
|
+
})
|
|
745
|
+
.join("");
|
|
746
|
+
|
|
747
|
+
grid.querySelectorAll("[data-id]").forEach((card) =>
|
|
748
|
+
card.addEventListener("click", () => openPlayer(games.find((g) => g.id === card.dataset.id)))
|
|
749
|
+
);
|
|
750
|
+
|
|
751
|
+
if (!gridShown) pop("#grid [data-fx]", { y: 22, scale: 0.88, delay: stagger(0.04, { startDelay: 0.2 }), stiff: 260, damp: 20 });
|
|
752
|
+
else pop("#grid [data-fx]", { y: 8, scale: 0.94, delay: stagger(0.015), stiff: 420, damp: 28 });
|
|
753
|
+
gridShown = true;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
/* ------------------------------ fetching ------------------------------ */
|
|
757
|
+
async function loadGames() {
|
|
758
|
+
if (!isConfigured()) {
|
|
759
|
+
el("setup-banner").classList.remove("hidden");
|
|
760
|
+
el("skeleton-grid").classList.add("hidden");
|
|
761
|
+
el("empty-title").textContent = "Not connected yet";
|
|
762
|
+
el("empty-sub").textContent = "Fill in CONFIG at the bottom of this file with your Supabase project details.";
|
|
763
|
+
el("empty-state").classList.remove("hidden");
|
|
764
|
+
el("empty-state").classList.add("flex");
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
try {
|
|
768
|
+
const rows = await unwrap(sb.from(CONFIG.gamesTable).select("*").order("sort_order").limit(200));
|
|
769
|
+
allGames = rows.filter((g) => g.url && g.enabled !== false);
|
|
770
|
+
const from = Number(el("count-num").textContent) || 0;
|
|
771
|
+
if (reduceMotion || from === allGames.length) el("count-num").textContent = allGames.length;
|
|
772
|
+
else animate(from, allGames.length, { duration: 1, delay: 0.3, ease: "easeOut", onUpdate: (v) => (el("count-num").textContent = Math.round(v)) });
|
|
773
|
+
renderCategoryBar(barShown ? undefined : "intro");
|
|
774
|
+
barShown = true;
|
|
775
|
+
renderGrid();
|
|
776
|
+
} catch (err) {
|
|
777
|
+
console.error("Failed to load games:", err);
|
|
778
|
+
if (allGames.length) { toast("Couldn't refresh the game list", "error"); return; }
|
|
779
|
+
el("retry").classList.remove("hidden");
|
|
780
|
+
el("skeleton-grid").classList.add("hidden");
|
|
781
|
+
el("empty-title").textContent = "Couldn't load games";
|
|
782
|
+
el("empty-sub").textContent = err?.message
|
|
783
|
+
? `Supabase said: "${err.message}". Check the browser console (F12) for the full error.`
|
|
784
|
+
: "Check your Supabase URL, anon key and the RLS policies from supabase-setup.sql.";
|
|
785
|
+
el("empty-state").classList.remove("hidden");
|
|
786
|
+
el("empty-state").classList.add("flex");
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
loadGames();
|
|
790
|
+
|
|
791
|
+
/* --------------------------- search / filter --------------------------- */
|
|
792
|
+
const searchEl = el("search"), clearBtn = el("search-clear");
|
|
793
|
+
let searchDebounce;
|
|
794
|
+
function applySearch() { searchTerm = searchEl.value.trim().toLowerCase(); renderGrid(); }
|
|
795
|
+
searchEl.addEventListener("input", () => {
|
|
796
|
+
clearBtn.classList.toggle("hidden", !searchEl.value);
|
|
797
|
+
clearBtn.classList.toggle("grid", !!searchEl.value);
|
|
798
|
+
clearTimeout(searchDebounce);
|
|
799
|
+
searchDebounce = setTimeout(applySearch, 120);
|
|
800
|
+
});
|
|
801
|
+
clearBtn.addEventListener("click", () => {
|
|
802
|
+
searchEl.value = "";
|
|
803
|
+
clearBtn.classList.add("hidden");
|
|
804
|
+
clearBtn.classList.remove("grid");
|
|
805
|
+
applySearch();
|
|
806
|
+
searchEl.focus();
|
|
807
|
+
});
|
|
808
|
+
searchEl.addEventListener("keydown", (e) => { if (e.key === "Escape" && searchEl.value) clearBtn.click(); });
|
|
809
|
+
el("retry").addEventListener("click", () => {
|
|
810
|
+
el("retry").classList.add("hidden");
|
|
811
|
+
el("empty-state").classList.add("hidden");
|
|
812
|
+
el("empty-state").classList.remove("flex");
|
|
813
|
+
el("skeleton-grid").classList.remove("hidden");
|
|
814
|
+
loadGames();
|
|
815
|
+
});
|
|
816
|
+
|
|
817
|
+
/* ------------------------------- dialogs ------------------------------- */
|
|
818
|
+
const isHidden = (id) => el(id).classList.contains("hidden");
|
|
819
|
+
let opener = null;
|
|
820
|
+
function lockBg(on) { document.querySelectorAll("body > header, body > main, body > footer, body > #panic-btn").forEach((n) => n.toggleAttribute("inert", on)); }
|
|
821
|
+
function beginDialog() { opener = document.activeElement; lockBg(true); }
|
|
822
|
+
function endDialog() { lockBg(false); if (opener && document.contains(opener)) opener.focus(); opener = null; }
|
|
823
|
+
const focusSoon = (node) => requestAnimationFrame(() => node && node.focus());
|
|
824
|
+
|
|
825
|
+
document.addEventListener("keydown", (e) => {
|
|
826
|
+
if (e.key === "Escape") {
|
|
827
|
+
if (!isHidden("player-modal")) closePlayer();
|
|
828
|
+
else if (!isHidden("admin-login-modal")) closeAdminLogin();
|
|
829
|
+
else if (!isHidden("settings-modal")) closeSettings();
|
|
830
|
+
else if (!isHidden("ann-modal")) closeAnnouncements();
|
|
831
|
+
else if (!isHidden("admin-panel")) escapeAdmin();
|
|
832
|
+
} else if (e.key === "/" && !e.ctrlKey && !e.metaKey && !e.altKey && allClosed()
|
|
833
|
+
&& !/^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement?.tagName || "")) {
|
|
834
|
+
e.preventDefault();
|
|
835
|
+
el("search").focus();
|
|
836
|
+
}
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
/* ------------------------------- player ------------------------------- */
|
|
840
|
+
function openPlayer(game) {
|
|
841
|
+
if (!game) return;
|
|
842
|
+
beginDialog();
|
|
843
|
+
el("player-title").textContent = game.name;
|
|
844
|
+
el("player-frame").title = game.name;
|
|
845
|
+
el("player-icon").src = iconSrcFor(game) || monogramSrc(game.name);
|
|
846
|
+
el("player-newtab").href = game.url;
|
|
847
|
+
el("player-loading").style.display = "grid";
|
|
848
|
+
el("player-frame").src = game.url;
|
|
849
|
+
el("player-modal").classList.remove("hidden");
|
|
850
|
+
document.documentElement.style.overflow = "hidden";
|
|
851
|
+
pop("#player-panel", { y: 20, scale: 0.94, stiff: 260, damp: 26 });
|
|
852
|
+
focusSoon(el("player-close"));
|
|
853
|
+
}
|
|
854
|
+
function closePlayer() {
|
|
855
|
+
fx("#player-panel", { opacity: [1, 0], scale: [1, 0.98] }, { duration: 0.18, ease: "easeIn" }).finished.then(() => {
|
|
856
|
+
el("player-modal").classList.add("hidden");
|
|
857
|
+
el("player-frame").src = "about:blank";
|
|
858
|
+
document.documentElement.style.overflow = "";
|
|
859
|
+
endDialog();
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
el("player-close").addEventListener("click", closePlayer);
|
|
863
|
+
document.querySelector("[data-player-close]").addEventListener("click", closePlayer);
|
|
864
|
+
el("player-fs").addEventListener("click", () => { const f = el("player-frame"); (f.requestFullscreen || f.webkitRequestFullscreen)?.call(f); });
|
|
865
|
+
|
|
866
|
+
/* ------------------------------ admin: PIN ------------------------------ */
|
|
867
|
+
function isUnlocked() { return sessionStorage.getItem(ADMIN_SESSION_KEY) === "1"; }
|
|
868
|
+
function openAdminLogin() {
|
|
869
|
+
beginDialog();
|
|
870
|
+
el("admin-login-modal").classList.remove("hidden");
|
|
871
|
+
pop("#admin-login-form", { y: 16, scale: 0.92, stiff: 380, damp: 24 });
|
|
872
|
+
resetPinBoxes();
|
|
873
|
+
focusSoon(pinInputs[0]);
|
|
874
|
+
}
|
|
875
|
+
function closeAdminLogin() {
|
|
876
|
+
el("admin-login-modal").classList.add("hidden");
|
|
877
|
+
el("admin-login-error").classList.add("hidden");
|
|
878
|
+
endDialog();
|
|
879
|
+
}
|
|
880
|
+
el("admin-trigger").addEventListener("click", () => { if (isUnlocked()) openAdminPanel(); else openAdminLogin(); });
|
|
881
|
+
document.querySelectorAll("[data-admin-login-close]").forEach((n) => n.addEventListener("click", closeAdminLogin));
|
|
882
|
+
|
|
883
|
+
const pinBoxesEl = el("pin-boxes");
|
|
884
|
+
pinBoxesEl.innerHTML = Array.from({ length: 6 })
|
|
885
|
+
.map((_, i) => `<input data-pin-idx="${i}" type="password" inputmode="numeric" pattern="[0-9]*" maxlength="1" autocomplete="off" aria-label="Digit ${i + 1} of 6"
|
|
886
|
+
class="h-12 w-full rounded-[12px] bg-white/[0.07] text-center text-[20px] tabular-nums outline-none ring-1 ring-inset ring-white/10 transition-shadow focus:ring-2 focus:ring-red-500" />`)
|
|
887
|
+
.join("");
|
|
888
|
+
const pinInputs = Array.from(pinBoxesEl.querySelectorAll("[data-pin-idx]"));
|
|
889
|
+
function resetPinBoxes() { pinInputs.forEach((i) => (i.value = "")); el("admin-pin").value = ""; }
|
|
890
|
+
function syncPinValue() { el("admin-pin").value = pinInputs.map((i) => i.value).join(""); }
|
|
891
|
+
function submitIfFull() { if (el("admin-pin").value.length === 6) el("admin-login-form").requestSubmit(); }
|
|
892
|
+
pinInputs.forEach((input, idx) => {
|
|
893
|
+
input.addEventListener("input", () => {
|
|
894
|
+
input.value = input.value.replace(/[^0-9]/g, "").slice(0, 1);
|
|
895
|
+
syncPinValue();
|
|
896
|
+
if (input.value && idx < pinInputs.length - 1) pinInputs[idx + 1].focus();
|
|
897
|
+
submitIfFull();
|
|
898
|
+
});
|
|
899
|
+
input.addEventListener("keydown", (e) => {
|
|
900
|
+
if (e.key === "Backspace" && !input.value && idx > 0) pinInputs[idx - 1].focus();
|
|
901
|
+
if (e.key === "ArrowLeft" && idx > 0) pinInputs[idx - 1].focus();
|
|
902
|
+
if (e.key === "ArrowRight" && idx < pinInputs.length - 1) pinInputs[idx + 1].focus();
|
|
903
|
+
});
|
|
904
|
+
input.addEventListener("paste", (e) => {
|
|
905
|
+
e.preventDefault();
|
|
906
|
+
const digits = (e.clipboardData.getData("text") || "").replace(/[^0-9]/g, "").slice(0, 6).split("");
|
|
907
|
+
digits.forEach((d, i) => pinInputs[i] && (pinInputs[i].value = d));
|
|
908
|
+
syncPinValue();
|
|
909
|
+
pinInputs[Math.min(digits.length, pinInputs.length - 1)]?.focus();
|
|
910
|
+
submitIfFull();
|
|
911
|
+
});
|
|
912
|
+
});
|
|
913
|
+
el("admin-login-form").addEventListener("submit", async (e) => {
|
|
914
|
+
e.preventDefault();
|
|
915
|
+
const errBox = el("admin-login-error");
|
|
916
|
+
syncPinValue();
|
|
917
|
+
if ((await sha256Hex(el("admin-pin").value)) === ADMIN_PIN_HASH) {
|
|
918
|
+
sessionStorage.setItem(ADMIN_SESSION_KEY, "1");
|
|
919
|
+
closeAdminLogin();
|
|
920
|
+
openAdminPanel();
|
|
921
|
+
} else {
|
|
922
|
+
errBox.textContent = "That PIN isn't right. Try again.";
|
|
923
|
+
errBox.classList.remove("hidden");
|
|
924
|
+
if (!reduceMotion) animate("#pin-boxes", { x: [0, -10, 10, -8, 8, -4, 0] }, { duration: 0.45 });
|
|
925
|
+
resetPinBoxes();
|
|
926
|
+
pinInputs[0]?.focus();
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
|
|
930
|
+
/* ---------------------------- admin: manage games ---------------------------- */
|
|
931
|
+
let adminRows = [], adminState = "loading", adminError = "";
|
|
932
|
+
let editingId = null, confirmingId = null, adminFilter = "", previewUrl = null;
|
|
933
|
+
|
|
934
|
+
const byOrder = (a, b) => (a.sort_order ?? 0) - (b.sort_order ?? 0);
|
|
935
|
+
const hostOf = (u) => { try { return new URL(u).hostname.replace(/^www\./, ""); } catch { return u; } };
|
|
936
|
+
const sr = (t) => `<span class="sr-only">${escapeHtml(t)}</span>`;
|
|
937
|
+
const rowIcon = (g) => iconSrcFor(g) || monogramSrc(g.name);
|
|
938
|
+
const adminSay = (msg) => { const n = el("admin-live"); n.textContent = ""; setTimeout(() => (n.textContent = msg), 60); };
|
|
939
|
+
|
|
940
|
+
function openAdminPanel() {
|
|
941
|
+
beginDialog();
|
|
942
|
+
editingId = null; confirmingId = null; adminFilter = ""; el("admin-filter").value = "";
|
|
943
|
+
annEditing = null; annConfirming = null; annLoaded = false; dirtyWarned = false; dirty.games = dirty.ann = false;
|
|
944
|
+
selectAdminTab("atab-games");
|
|
945
|
+
el("admin-panel").classList.remove("hidden");
|
|
946
|
+
pop("#admin-panel-card", { y: 24, scale: 0.97, stiff: 300, damp: 28 });
|
|
947
|
+
focusSoon(el("admin-title"));
|
|
948
|
+
loadAdmin();
|
|
949
|
+
}
|
|
950
|
+
function closeAdminPanel() { el("admin-panel").classList.add("hidden"); endDialog(); }
|
|
951
|
+
el("admin-close").addEventListener("click", closeAdminPanel);
|
|
952
|
+
el("admin-logout").addEventListener("click", () => {
|
|
953
|
+
sessionStorage.removeItem(ADMIN_SESSION_KEY);
|
|
954
|
+
closeAdminPanel();
|
|
955
|
+
toast("Admin locked");
|
|
956
|
+
});
|
|
957
|
+
|
|
958
|
+
async function loadAdmin() {
|
|
959
|
+
adminState = "loading";
|
|
960
|
+
renderAdmin();
|
|
961
|
+
try {
|
|
962
|
+
const rows = await unwrap(sb.from(CONFIG.gamesTable).select("*").order("sort_order").limit(200));
|
|
963
|
+
adminRows = rows.slice().sort(byOrder);
|
|
964
|
+
adminState = "ready";
|
|
965
|
+
} catch (err) {
|
|
966
|
+
adminState = "error";
|
|
967
|
+
adminError = err?.message || "Couldn't load your games.";
|
|
968
|
+
}
|
|
969
|
+
renderAdmin();
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
function formHtml(g) {
|
|
973
|
+
const isEdit = !!g;
|
|
974
|
+
const v = (x) => escapeHtml(x ?? "");
|
|
975
|
+
const cats = [...new Set(adminRows.map((r) => r.category).filter(Boolean))];
|
|
976
|
+
const hasIcon = isEdit && (g.icon_file_id || g.icon_url);
|
|
977
|
+
const base = escapeHtml(isEdit ? rowIcon(g) : monogramSrc("+"));
|
|
978
|
+
return `<form id="game-form" novalidate aria-labelledby="game-form-title" class="glass-lite mb-4 rounded-2xl p-4">
|
|
979
|
+
<h3 id="game-form-title" class="text-[16px] font-semibold">${isEdit ? `Edit ${v(g.name)}` : "Add a game"}</h3>
|
|
980
|
+
<div class="mt-4 grid gap-4 sm:grid-cols-2">
|
|
981
|
+
<div>
|
|
982
|
+
<label for="gf-name" class="text-[13px] font-medium text-ink-200">Name</label>
|
|
983
|
+
<input id="gf-name" required autocomplete="off" aria-describedby="gf-name-err" value="${v(g?.name)}" class="field mt-1.5" />
|
|
984
|
+
<p id="gf-name-err" role="alert" class="mt-1.5 hidden text-[13px] text-red-300"></p>
|
|
985
|
+
</div>
|
|
986
|
+
<div>
|
|
987
|
+
<label for="gf-category" class="text-[13px] font-medium text-ink-200">Category <span class="font-normal text-ink-300">(optional)</span></label>
|
|
988
|
+
<input id="gf-category" list="category-options" autocomplete="off" value="${v(g?.category)}" class="field mt-1.5" />
|
|
989
|
+
<datalist id="category-options">${cats.map((c) => `<option value="${v(c)}"></option>`).join("")}</datalist>
|
|
990
|
+
</div>
|
|
991
|
+
<div class="sm:col-span-2">
|
|
992
|
+
<label for="gf-url" class="text-[13px] font-medium text-ink-200">Game link</label>
|
|
993
|
+
<input id="gf-url" type="url" inputmode="url" required autocomplete="off" spellcheck="false" placeholder="https://" aria-describedby="gf-url-hint gf-url-err" value="${v(g?.url)}" class="field mt-1.5" />
|
|
994
|
+
<p id="gf-url-hint" class="mt-1.5 text-[13px] text-ink-300">The page that opens when someone taps the game.</p>
|
|
995
|
+
<p id="gf-url-err" role="alert" class="mt-1.5 hidden text-[13px] text-red-300"></p>
|
|
996
|
+
</div>
|
|
997
|
+
</div>
|
|
998
|
+
<fieldset class="mt-4 min-w-0">
|
|
999
|
+
<legend class="text-[13px] font-medium text-ink-200">Icon</legend>
|
|
1000
|
+
<div class="mt-2 flex items-start gap-4">
|
|
1001
|
+
<img id="gf-preview" src="${base}" data-base="${base}" alt="Icon preview" class="tile-img h-16 w-16 shrink-0 rounded-[22.37%] object-cover" onerror="this.onerror=null;this.src=this.dataset.base" />
|
|
1002
|
+
<div class="grid min-w-0 flex-1 gap-3">
|
|
1003
|
+
<div>
|
|
1004
|
+
<label for="gf-file" class="text-[13px] text-ink-300">Upload an image</label>
|
|
1005
|
+
<input id="gf-file" type="file" accept="image/*" aria-describedby="gf-file-err" class="mt-1.5 w-full text-[13px] text-ink-300 file:mr-3 file:rounded-full file:border-0 file:bg-white/10 file:px-3.5 file:py-1.5 file:text-[13px] file:font-medium file:text-ink-50" />
|
|
1006
|
+
<p id="gf-file-err" role="alert" class="mt-1.5 hidden text-[13px] text-red-300"></p>
|
|
1007
|
+
</div>
|
|
1008
|
+
<div>
|
|
1009
|
+
<label for="gf-iconurl" class="text-[13px] text-ink-300">…or paste an image link</label>
|
|
1010
|
+
<input id="gf-iconurl" type="url" inputmode="url" autocomplete="off" spellcheck="false" placeholder="https://" aria-describedby="gf-iconurl-err" value="${v(g?.icon_url)}" class="field mt-1.5" />
|
|
1011
|
+
<p id="gf-iconurl-err" role="alert" class="mt-1.5 hidden text-[13px] text-red-300"></p>
|
|
1012
|
+
</div>
|
|
1013
|
+
${hasIcon ? `<label class="flex items-center gap-2 text-[13px] text-ink-200"><input id="gf-remove" type="checkbox" class="h-4 w-4 accent-red-500" /> Remove the current icon (shows initials instead)</label>` : ""}
|
|
1014
|
+
</div>
|
|
1015
|
+
</div>
|
|
1016
|
+
</fieldset>
|
|
1017
|
+
<label class="mt-4 flex cursor-pointer items-center gap-3 text-[14px]"><input id="gf-enabled" type="checkbox" role="switch" class="switch" ${g?.enabled === false ? "" : "checked"} /> Show on the site</label>
|
|
1018
|
+
<div class="mt-5 flex flex-wrap items-center gap-2">
|
|
1019
|
+
<button type="submit" id="gf-submit" class="btn btn-primary">${isEdit ? "Save changes" : "Add game"}</button>
|
|
1020
|
+
<button type="button" data-act="cancel-form" class="btn btn-ghost">Cancel</button>
|
|
1021
|
+
</div>
|
|
1022
|
+
</form>`;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
function rowHtml(g, idx, canMove) {
|
|
1026
|
+
if (editingId === g.id) return `<li data-row="${g.id}">${formHtml(g)}</li>`;
|
|
1027
|
+
const n = escapeHtml(g.name);
|
|
1028
|
+
const off = g.enabled === false;
|
|
1029
|
+
const dis = editingId ? "disabled" : "";
|
|
1030
|
+
const meta = [g.category, hostOf(g.url)].filter(Boolean).map(escapeHtml).join(" · ");
|
|
1031
|
+
const arrow = (dir, d, label, disabled) => `<button type="button" data-act="${dir}" data-id="${g.id}" aria-label="${label} ${n}" ${disabled || dis ? "disabled" : ""} class="glass-lite icon-btn"><svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg></button>`;
|
|
1032
|
+
const actions = confirmingId === g.id
|
|
1033
|
+
? `<div role="group" aria-label="Confirm delete" class="mt-3 rounded-xl bg-red-500/10 p-3 ring-1 ring-red-500/30">
|
|
1034
|
+
<p class="text-[14px]">Delete <strong>${n}</strong>? This can't be undone.</p>
|
|
1035
|
+
<div class="mt-3 flex gap-2">
|
|
1036
|
+
<button type="button" id="cancel-delete" data-act="cancel-delete" data-id="${g.id}" class="btn btn-ghost">Cancel</button>
|
|
1037
|
+
<button type="button" data-act="confirm-delete" data-id="${g.id}" class="btn btn-danger">Delete</button>
|
|
1038
|
+
</div>
|
|
1039
|
+
</div>`
|
|
1040
|
+
: `<div class="mt-3 flex flex-wrap items-center gap-2">
|
|
1041
|
+
${canMove ? arrow("up", "m6 15 6-6 6 6", "Move up:", idx === 0) + arrow("down", "m6 9 6 6 6-6", "Move down:", idx === adminRows.length - 1) : ""}
|
|
1042
|
+
<button type="button" data-act="edit" data-id="${g.id}" ${dis} class="btn btn-ghost">Edit${sr(" " + g.name)}</button>
|
|
1043
|
+
<button type="button" data-act="delete" data-id="${g.id}" ${dis} class="btn btn-ghost ml-auto hover:!text-red-300">Delete${sr(" " + g.name)}</button>
|
|
1044
|
+
</div>`;
|
|
1045
|
+
return `<li data-row="${g.id}" class="glass-lite rounded-2xl p-3">
|
|
1046
|
+
<div class="flex items-center gap-3">
|
|
1047
|
+
<img src="${escapeHtml(rowIcon(g))}" alt="" class="tile-img h-12 w-12 shrink-0 rounded-[22.37%] object-cover ${off ? "opacity-50" : ""}" onerror="this.onerror=null;this.src='${monogramSrc(g.name)}'" />
|
|
1048
|
+
<div class="min-w-0 flex-1">
|
|
1049
|
+
<p class="truncate text-[15px] font-medium">${n}${off ? '<span class="tag">Hidden</span>' : ""}</p>
|
|
1050
|
+
<p class="truncate text-[13px] text-ink-300">${meta}</p>
|
|
1051
|
+
</div>
|
|
1052
|
+
<label class="flex shrink-0 cursor-pointer items-center gap-2 text-[13px] text-ink-200">
|
|
1053
|
+
<input type="checkbox" role="switch" class="switch" data-toggle="${g.id}" ${off ? "" : "checked"} ${dis} />
|
|
1054
|
+
<span>Visible${sr(" on site: " + g.name)}</span>
|
|
1055
|
+
</label>
|
|
1056
|
+
</div>
|
|
1057
|
+
${actions}
|
|
1058
|
+
</li>`;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
function renderAdmin(focusSels = []) {
|
|
1062
|
+
dirty.games = false;
|
|
1063
|
+
el("admin-form-slot").innerHTML = editingId === "new" ? formHtml(null) : "";
|
|
1064
|
+
const list = el("admin-list"), sum = gamesSum;
|
|
1065
|
+
el("admin-add").disabled = !!editingId;
|
|
1066
|
+
el("admin-filter").disabled = !!editingId;
|
|
1067
|
+
if (adminState === "loading") { sum.textContent = ""; list.innerHTML = `<li class="py-8 text-center text-[14px] text-ink-300">Loading games…</li>`; return; }
|
|
1068
|
+
if (adminState === "error") {
|
|
1069
|
+
sum.textContent = "";
|
|
1070
|
+
list.innerHTML = `<li class="py-8 text-center"><p class="text-[14px] text-red-300">${escapeHtml(adminError)}</p><button type="button" data-act="retry" class="btn btn-ghost mt-3">Try again</button></li>`;
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
const q = adminFilter;
|
|
1074
|
+
const rows = q ? adminRows.filter((g) => `${g.name} ${g.category || ""}`.toLowerCase().includes(q)) : adminRows;
|
|
1075
|
+
const visible = adminRows.filter((g) => g.enabled !== false).length;
|
|
1076
|
+
sum.textContent = q ? `Showing ${rows.length} of ${adminRows.length}` : `${adminRows.length} ${adminRows.length === 1 ? "game" : "games"} · ${visible} visible`;
|
|
1077
|
+
list.innerHTML = rows.length
|
|
1078
|
+
? rows.map((g) => rowHtml(g, adminRows.indexOf(g), !q)).join("")
|
|
1079
|
+
: `<li class="py-8 text-center text-[14px] text-ink-300">${adminRows.length ? `No games match “${escapeHtml(adminFilter)}”.` : "No games yet. Choose “Add game” to add your first one."}</li>`;
|
|
1080
|
+
if (editingId) { const n = el("gf-name"); n.focus(); n.scrollIntoView({ block: "nearest" }); return; }
|
|
1081
|
+
for (const sel of focusSels) {
|
|
1082
|
+
const t = el("admin-panel-card").querySelector(sel);
|
|
1083
|
+
if (t && !t.disabled) { t.focus(); break; }
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
function cancelForm() {
|
|
1088
|
+
const id = editingId;
|
|
1089
|
+
editingId = null;
|
|
1090
|
+
renderAdmin([id && id !== "new" ? `[data-act="edit"][data-id="${id}"]` : "#admin-add"]);
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
el("admin-add").addEventListener("click", () => { editingId = "new"; confirmingId = null; renderAdmin(); });
|
|
1094
|
+
el("admin-filter").addEventListener("input", (e) => { adminFilter = e.target.value.trim().toLowerCase(); renderAdmin(); });
|
|
1095
|
+
|
|
1096
|
+
el("admin-body").addEventListener("click", (e) => {
|
|
1097
|
+
const b = e.target.closest("[data-act]");
|
|
1098
|
+
if (!b || b.disabled) return;
|
|
1099
|
+
const { act, id } = b.dataset;
|
|
1100
|
+
if (act === "retry") loadAdmin();
|
|
1101
|
+
else if (act === "edit") { editingId = id; confirmingId = null; renderAdmin(); }
|
|
1102
|
+
else if (act === "cancel-form") cancelForm();
|
|
1103
|
+
else if (act === "delete") { confirmingId = id; renderAdmin(["#cancel-delete"]); }
|
|
1104
|
+
else if (act === "cancel-delete") { confirmingId = null; renderAdmin([`[data-act="delete"][data-id="${id}"]`]); }
|
|
1105
|
+
else if (act === "confirm-delete") { b.disabled = true; b.textContent = "Deleting…"; deleteGame(id); }
|
|
1106
|
+
else if (act === "up") moveGame(id, -1);
|
|
1107
|
+
else if (act === "down") moveGame(id, 1);
|
|
1108
|
+
});
|
|
1109
|
+
el("admin-body").addEventListener("change", (e) => {
|
|
1110
|
+
const t = e.target;
|
|
1111
|
+
if (t.matches("[data-toggle]")) toggleGame(t.dataset.toggle, t.checked);
|
|
1112
|
+
else if (t.id === "gf-file" || t.id === "gf-remove") updatePreview();
|
|
1113
|
+
});
|
|
1114
|
+
el("admin-body").addEventListener("input", (e) => {
|
|
1115
|
+
const t = e.target;
|
|
1116
|
+
if (t.getAttribute?.("aria-invalid")) setErr(t.id, "");
|
|
1117
|
+
if (t.id === "gf-iconurl") updatePreview();
|
|
1118
|
+
});
|
|
1119
|
+
el("admin-body").addEventListener("submit", (e) => { if (e.target.id === "game-form") submitGameForm(e); });
|
|
1120
|
+
|
|
1121
|
+
function updatePreview() {
|
|
1122
|
+
const img = el("gf-preview"), file = el("gf-file").files[0], url = el("gf-iconurl").value.trim();
|
|
1123
|
+
if (previewUrl) { URL.revokeObjectURL(previewUrl); previewUrl = null; }
|
|
1124
|
+
if (el("gf-remove")?.checked) img.src = monogramSrc(el("gf-name").value || "?");
|
|
1125
|
+
else if (file && file.type.startsWith("image/")) img.src = previewUrl = URL.createObjectURL(file);
|
|
1126
|
+
else if (isHttp(url)) img.src = url;
|
|
1127
|
+
else img.src = img.dataset.base;
|
|
1128
|
+
}
|
|
1129
|
+
function setErr(id, msg) {
|
|
1130
|
+
const inp = el(id), p = el(id + "-err");
|
|
1131
|
+
p.textContent = msg || "";
|
|
1132
|
+
p.classList.toggle("hidden", !msg);
|
|
1133
|
+
if (msg) inp.setAttribute("aria-invalid", "true"); else inp.removeAttribute("aria-invalid");
|
|
1134
|
+
}
|
|
1135
|
+
function validateGameForm() {
|
|
1136
|
+
const name = el("gf-name").value.trim(), url = el("gf-url").value.trim(), iu = el("gf-iconurl").value.trim(), f = el("gf-file").files[0];
|
|
1137
|
+
const checks = [
|
|
1138
|
+
["gf-name", name ? "" : "Enter a name."],
|
|
1139
|
+
["gf-url", !url ? "Enter the game link." : isHttp(url) ? "" : "Enter a full link that starts with https://"],
|
|
1140
|
+
["gf-iconurl", !iu || isHttp(iu) ? "" : "Enter a full link that starts with https://"],
|
|
1141
|
+
["gf-file", !f || f.type.startsWith("image/") ? "" : "Choose an image file."],
|
|
1142
|
+
];
|
|
1143
|
+
let first = null;
|
|
1144
|
+
checks.forEach(([id, msg]) => { setErr(id, msg); if (msg && !first) first = id; });
|
|
1145
|
+
if (first) el(first).focus();
|
|
1146
|
+
return !first;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
function flashRow(id) {
|
|
1150
|
+
const li = el("admin-list").querySelector(`[data-row="${id}"]`);
|
|
1151
|
+
if (!li) return;
|
|
1152
|
+
li.scrollIntoView({ block: "nearest" });
|
|
1153
|
+
if (!reduceMotion) animate(li, { backgroundColor: ["rgba(240,26,54,0.4)", "rgba(255,255,255,0.07)"] }, { duration: 1.2 });
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
async function submitGameForm(e) {
|
|
1157
|
+
e.preventDefault();
|
|
1158
|
+
if (!validateGameForm()) return;
|
|
1159
|
+
const isEdit = editingId && editingId !== "new";
|
|
1160
|
+
const existing = isEdit ? adminRows.find((r) => r.id === editingId) : null;
|
|
1161
|
+
const name = el("gf-name").value.trim(), url = el("gf-url").value.trim(), category = el("gf-category").value.trim();
|
|
1162
|
+
const iconField = el("gf-iconurl").value.trim(), file = el("gf-file").files[0], enabled = el("gf-enabled").checked, remove = !!el("gf-remove")?.checked;
|
|
1163
|
+
const btn = el("gf-submit"), label = btn.textContent;
|
|
1164
|
+
btn.disabled = true; btn.textContent = "Saving…";
|
|
1165
|
+
let uploadedPath = null, oldFile = null;
|
|
1166
|
+
try {
|
|
1167
|
+
let icon_file_id = existing?.icon_file_id || "", icon_url = existing?.icon_url || "";
|
|
1168
|
+
if (remove) { oldFile = icon_file_id; icon_file_id = ""; icon_url = ""; }
|
|
1169
|
+
else if (file) {
|
|
1170
|
+
uploadedPath = (await unwrap(sb.storage.from(CONFIG.iconsBucket).upload(crypto.randomUUID(), file))).path;
|
|
1171
|
+
oldFile = icon_file_id; icon_file_id = uploadedPath; icon_url = "";
|
|
1172
|
+
} else if (iconField && iconField !== icon_url) { oldFile = icon_file_id; icon_file_id = ""; icon_url = iconField; }
|
|
1173
|
+
else if (!iconField && icon_url && !icon_file_id) icon_url = "";
|
|
1174
|
+
const data = { name, url, category, icon_file_id, icon_url, enabled };
|
|
1175
|
+
let row;
|
|
1176
|
+
if (isEdit) {
|
|
1177
|
+
row = await unwrap(sb.from(CONFIG.gamesTable).update(data).eq("id", editingId).select().single());
|
|
1178
|
+
adminRows = adminRows.map((r) => (r.id === row.id ? row : r));
|
|
1179
|
+
} else {
|
|
1180
|
+
data.sort_order = adminRows.reduce((m, r) => Math.max(m, r.sort_order ?? -1), -1) + 1;
|
|
1181
|
+
row = await unwrap(sb.from(CONFIG.gamesTable).insert(data).select().single());
|
|
1182
|
+
adminRows = [...adminRows, row].sort(byOrder);
|
|
1183
|
+
}
|
|
1184
|
+
if (oldFile) sb.storage.from(CONFIG.iconsBucket).remove([oldFile]).catch(() => {});
|
|
1185
|
+
editingId = null;
|
|
1186
|
+
renderAdmin([`[data-act="edit"][data-id="${row.id}"]`]);
|
|
1187
|
+
flashRow(row.id);
|
|
1188
|
+
toast(isEdit ? `Saved ${name}` : `Added ${name}`);
|
|
1189
|
+
loadGames();
|
|
1190
|
+
} catch (err) {
|
|
1191
|
+
if (uploadedPath) sb.storage.from(CONFIG.iconsBucket).remove([uploadedPath]).catch(() => {});
|
|
1192
|
+
btn.disabled = false; btn.textContent = label;
|
|
1193
|
+
toast(err?.message || "Couldn't save. Check your connection and try again.", "error");
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
async function toggleGame(id, on) {
|
|
1198
|
+
const row = adminRows.find((r) => r.id === id);
|
|
1199
|
+
if (!row) return;
|
|
1200
|
+
const prev = row.enabled !== false;
|
|
1201
|
+
row.enabled = on;
|
|
1202
|
+
renderAdmin([`[data-toggle="${id}"]`]);
|
|
1203
|
+
try {
|
|
1204
|
+
await unwrap(sb.from(CONFIG.gamesTable).update({ enabled: on }).eq("id", id));
|
|
1205
|
+
adminSay(`${row.name} is now ${on ? "visible" : "hidden"}`);
|
|
1206
|
+
loadGames();
|
|
1207
|
+
} catch (err) {
|
|
1208
|
+
row.enabled = prev;
|
|
1209
|
+
renderAdmin([`[data-toggle="${id}"]`]);
|
|
1210
|
+
toast(err?.message || "Couldn't update visibility", "error");
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
async function moveGame(id, dir) {
|
|
1215
|
+
const list = [...adminRows].sort(byOrder);
|
|
1216
|
+
const i = list.findIndex((r) => r.id === id), j = i + dir;
|
|
1217
|
+
if (i < 0 || j < 0 || j >= list.length) return;
|
|
1218
|
+
const prev = list.map((r) => ({ ...r }));
|
|
1219
|
+
[list[i], list[j]] = [list[j], list[i]];
|
|
1220
|
+
const changes = [];
|
|
1221
|
+
list.forEach((r, k) => { if (r.sort_order !== k) { r.sort_order = k; changes.push(r); } });
|
|
1222
|
+
adminRows = list;
|
|
1223
|
+
const name = list[j].name;
|
|
1224
|
+
renderAdmin([`[data-act="${dir < 0 ? "up" : "down"}"][data-id="${id}"]`, `[data-act="${dir < 0 ? "down" : "up"}"][data-id="${id}"]`]);
|
|
1225
|
+
adminSay(`${name} moved to position ${j + 1} of ${list.length}`);
|
|
1226
|
+
try {
|
|
1227
|
+
await Promise.all(changes.map((r) => unwrap(sb.from(CONFIG.gamesTable).update({ sort_order: r.sort_order }).eq("id", r.id))));
|
|
1228
|
+
loadGames();
|
|
1229
|
+
} catch (err) {
|
|
1230
|
+
adminRows = prev;
|
|
1231
|
+
renderAdmin();
|
|
1232
|
+
toast(err?.message || "Couldn't change the order", "error");
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
async function deleteGame(id) {
|
|
1237
|
+
const row = adminRows.find((r) => r.id === id);
|
|
1238
|
+
if (!row) return;
|
|
1239
|
+
try {
|
|
1240
|
+
await unwrap(sb.from(CONFIG.gamesTable).delete().eq("id", id));
|
|
1241
|
+
if (row.icon_file_id) sb.storage.from(CONFIG.iconsBucket).remove([row.icon_file_id]).catch(() => {});
|
|
1242
|
+
adminRows = adminRows.filter((r) => r.id !== id);
|
|
1243
|
+
confirmingId = null;
|
|
1244
|
+
renderAdmin(["#admin-add"]);
|
|
1245
|
+
toast(`Deleted ${row.name}`);
|
|
1246
|
+
loadGames();
|
|
1247
|
+
} catch (err) {
|
|
1248
|
+
renderAdmin(["#cancel-delete"]);
|
|
1249
|
+
toast(err?.message || "Couldn't delete. Try again.", "error");
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
/* ============================ dialogs: shared helpers ============================ */
|
|
1254
|
+
const allClosed = () => ["player-modal", "admin-login-modal", "admin-panel", "settings-modal", "ann-modal"].every(isHidden);
|
|
1255
|
+
function openModal(id, card, focusId) {
|
|
1256
|
+
beginDialog();
|
|
1257
|
+
el(id).classList.remove("hidden");
|
|
1258
|
+
pop("#" + card, { y: 18, scale: 0.95, stiff: 320, damp: 26 });
|
|
1259
|
+
focusSoon(el(focusId));
|
|
1260
|
+
}
|
|
1261
|
+
function closeModal(id) { el(id).classList.add("hidden"); endDialog(); }
|
|
1262
|
+
|
|
1263
|
+
// Click (or tap) on the dimmed area outside a dialog closes it. Both the press and the release must land on the backdrop,
|
|
1264
|
+
// so dragging a text selection out of a dialog never closes it.
|
|
1265
|
+
let pressedEl = null;
|
|
1266
|
+
document.addEventListener("pointerdown", (e) => { pressedEl = e.target; }, true);
|
|
1267
|
+
const BACKDROPS = { login: () => closeAdminLogin(), admin: () => tryCloseAdmin(), settings: () => closeSettings(), ann: () => closeAnnouncements() };
|
|
1268
|
+
document.querySelectorAll("[data-backdrop]").forEach((b) =>
|
|
1269
|
+
b.addEventListener("click", (e) => { if (e.target === b && pressedEl === b) BACKDROPS[b.dataset.backdrop](); })
|
|
1270
|
+
);
|
|
1271
|
+
|
|
1272
|
+
/* ============================ tabs (settings + admin) ============================ */
|
|
1273
|
+
function wireTabs(list, onSelect) {
|
|
1274
|
+
const tabs = [...list.querySelectorAll('[role="tab"]')];
|
|
1275
|
+
const activate = (t, focus) => {
|
|
1276
|
+
tabs.forEach((x) => {
|
|
1277
|
+
const on = x === t;
|
|
1278
|
+
x.setAttribute("aria-selected", String(on));
|
|
1279
|
+
x.tabIndex = on ? 0 : -1;
|
|
1280
|
+
document.getElementById(x.getAttribute("aria-controls")).hidden = !on;
|
|
1281
|
+
});
|
|
1282
|
+
if (focus) t.focus();
|
|
1283
|
+
onSelect?.(t);
|
|
1284
|
+
};
|
|
1285
|
+
tabs.forEach((t) => t.addEventListener("click", () => activate(t)));
|
|
1286
|
+
list.addEventListener("keydown", (e) => {
|
|
1287
|
+
const i = tabs.indexOf(document.activeElement);
|
|
1288
|
+
if (i < 0) return;
|
|
1289
|
+
let n = -1;
|
|
1290
|
+
if (e.key === "ArrowRight") n = (i + 1) % tabs.length;
|
|
1291
|
+
else if (e.key === "ArrowLeft") n = (i - 1 + tabs.length) % tabs.length;
|
|
1292
|
+
else if (e.key === "Home") n = 0;
|
|
1293
|
+
else if (e.key === "End") n = tabs.length - 1;
|
|
1294
|
+
if (n >= 0) { e.preventDefault(); activate(tabs[n], true); }
|
|
1295
|
+
});
|
|
1296
|
+
return (id) => activate(tabs.find((t) => t.id === id));
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
/* ============================ admin: tabs, unsaved-changes guard ============================ */
|
|
1300
|
+
let adminTab = "games", annLoaded = false, annEditing = null, annConfirming = null, dirtyWarned = false;
|
|
1301
|
+
const dirty = { games: false, ann: false };
|
|
1302
|
+
const adminSummaries = { games: "", ann: "" };
|
|
1303
|
+
function setSummary(tab, text) { adminSummaries[tab] = text; if (tab === adminTab) el("admin-summary").textContent = text; }
|
|
1304
|
+
const gamesSum = { set textContent(v) { setSummary("games", v); } };
|
|
1305
|
+
const selectAdminTab = wireTabs(el("admin-tabs"), (t) => {
|
|
1306
|
+
adminTab = t.dataset.atab;
|
|
1307
|
+
el("admin-summary").textContent = adminSummaries[adminTab];
|
|
1308
|
+
if (adminTab === "ann" && !annLoaded) { annLoaded = true; loadAnnAdmin(); }
|
|
1309
|
+
});
|
|
1310
|
+
for (const evt of ["input", "change"]) {
|
|
1311
|
+
el("admin-panel-card").addEventListener(evt, (e) => { if (e.target.closest?.("form")) { dirty[adminTab] = true; dirtyWarned = false; } });
|
|
1312
|
+
}
|
|
1313
|
+
function tryCloseAdmin() {
|
|
1314
|
+
if (dirty[adminTab] && !dirtyWarned) {
|
|
1315
|
+
dirtyWarned = true;
|
|
1316
|
+
if (!reduceMotion) animate("#admin-panel-card", { x: [0, -8, 8, -5, 5, 0] }, { duration: 0.35 });
|
|
1317
|
+
toast("You have unsaved changes. Click outside again to discard them.");
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1320
|
+
dirtyWarned = false;
|
|
1321
|
+
closeAdminPanel();
|
|
1322
|
+
}
|
|
1323
|
+
function escapeAdmin() {
|
|
1324
|
+
if (adminTab === "ann") {
|
|
1325
|
+
if (annConfirming) { const id = annConfirming; annConfirming = null; renderAnnAdmin([`[data-aact="delete"][data-id="${id}"]`]); }
|
|
1326
|
+
else if (annEditing) cancelAnnForm();
|
|
1327
|
+
else closeAdminPanel();
|
|
1328
|
+
} else if (confirmingId) { const id = confirmingId; confirmingId = null; renderAdmin([`[data-act="delete"][data-id="${id}"]`]); }
|
|
1329
|
+
else if (editingId) cancelForm();
|
|
1330
|
+
else closeAdminPanel();
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
/* ============================ announcements: visitors ============================ */
|
|
1334
|
+
const SEEN_KEY = "mlv2_seen_announcements";
|
|
1335
|
+
const getSeen = () => { try { const v = JSON.parse(localStorage.getItem(SEEN_KEY)); return Array.isArray(v) ? v : []; } catch { return []; } };
|
|
1336
|
+
const markSeen = (ids) => { try { localStorage.setItem(SEEN_KEY, JSON.stringify([...new Set([...getSeen(), ...ids])].slice(-200))); } catch { /* storage blocked */ } };
|
|
1337
|
+
let announcements = [], annShown = [], annAutoShown = false;
|
|
1338
|
+
const fmtDate = (iso) => new Date(iso).toLocaleDateString(undefined, { month: "short", day: "numeric", year: "numeric" });
|
|
1339
|
+
const annImage = (a) => (a.image_file_id ? `${CONFIG.supabaseUrl}/storage/v1/object/public/${CONFIG.iconsBucket}/${a.image_file_id}` : a.image_url || "");
|
|
1340
|
+
|
|
1341
|
+
function annCard(a) {
|
|
1342
|
+
const img = annImage(a);
|
|
1343
|
+
return `<article class="rounded-[28px] bg-white/[0.06] p-2 ring-1 ring-inset ring-white/10">
|
|
1344
|
+
${img ? `<img src="${escapeHtml(img)}" alt="" loading="lazy" class="aspect-[16/9] w-full rounded-[20px] object-cover" onerror="this.remove()" />` : ""}
|
|
1345
|
+
<div class="px-3.5 pb-3 pt-3">
|
|
1346
|
+
<h3 class="text-[17px] font-bold leading-snug">${escapeHtml(a.title)} <span aria-hidden="true">•</span> <time datetime="${escapeHtml(a.created_at)}">${escapeHtml(fmtDate(a.created_at))}</time></h3>
|
|
1347
|
+
${a.content ? `<p class="mt-1 whitespace-pre-line break-words text-[15px] leading-relaxed text-ink-100">${escapeHtml(a.content)}</p>` : ""}
|
|
1348
|
+
</div>
|
|
1349
|
+
</article>`;
|
|
1350
|
+
}
|
|
1351
|
+
function refreshBell() {
|
|
1352
|
+
const seen = getSeen();
|
|
1353
|
+
const unseen = announcements.filter((a) => !seen.includes(a.id)).length;
|
|
1354
|
+
el("bell-btn").hidden = announcements.length === 0;
|
|
1355
|
+
el("bell-dot").hidden = unseen === 0;
|
|
1356
|
+
el("bell-btn").setAttribute("aria-label", unseen ? `Announcements (${unseen} new)` : "Announcements");
|
|
1357
|
+
}
|
|
1358
|
+
function openAnnouncements(list) {
|
|
1359
|
+
if (!list.length) return;
|
|
1360
|
+
annShown = list;
|
|
1361
|
+
el("ann-list").innerHTML = list.map(annCard).join("");
|
|
1362
|
+
el("ann-list").scrollTop = 0;
|
|
1363
|
+
openModal("ann-modal", "ann-card", "ann-title");
|
|
1364
|
+
}
|
|
1365
|
+
function closeAnnouncements() {
|
|
1366
|
+
markSeen(annShown.map((a) => a.id));
|
|
1367
|
+
annShown = [];
|
|
1368
|
+
closeModal("ann-modal");
|
|
1369
|
+
refreshBell();
|
|
1370
|
+
}
|
|
1371
|
+
async function loadAnnouncements() {
|
|
1372
|
+
if (!isConfigured()) return;
|
|
1373
|
+
try {
|
|
1374
|
+
const rows = await unwrap(sb.from(CONFIG.announcementsTable).select("*").order("created_at", { ascending: false }).limit(20));
|
|
1375
|
+
announcements = rows.filter((a) => a.enabled !== false && a.title);
|
|
1376
|
+
} catch (err) { console.warn("Announcements unavailable:", err); return; }
|
|
1377
|
+
refreshBell();
|
|
1378
|
+
const seen = getSeen();
|
|
1379
|
+
const unseen = announcements.filter((a) => !seen.includes(a.id));
|
|
1380
|
+
if (settings.announceOnOpen && unseen.length && !annAutoShown) {
|
|
1381
|
+
annAutoShown = true;
|
|
1382
|
+
setTimeout(() => { if (allClosed()) openAnnouncements(unseen); }, 900);
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
el("bell-btn").addEventListener("click", () => openAnnouncements(announcements));
|
|
1386
|
+
el("ann-close").addEventListener("click", closeAnnouncements);
|
|
1387
|
+
el("ann-done").addEventListener("click", closeAnnouncements);
|
|
1388
|
+
|
|
1389
|
+
/* ============================ announcements: admin ============================ */
|
|
1390
|
+
let annRows = [], annState = "idle", annError = "", annPreviewUrl = null;
|
|
1391
|
+
|
|
1392
|
+
async function loadAnnAdmin() {
|
|
1393
|
+
if (!isConfigured()) { annState = "unconfigured"; renderAnnAdmin(); return; }
|
|
1394
|
+
annState = "loading";
|
|
1395
|
+
renderAnnAdmin();
|
|
1396
|
+
try {
|
|
1397
|
+
const rows = await unwrap(sb.from(CONFIG.announcementsTable).select("*").order("created_at", { ascending: false }).limit(100));
|
|
1398
|
+
annRows = rows;
|
|
1399
|
+
annState = "ready";
|
|
1400
|
+
} catch (err) { annState = "error"; annError = err?.message || "Couldn't load announcements."; }
|
|
1401
|
+
renderAnnAdmin();
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
function annFormHtml(a) {
|
|
1405
|
+
const v = (x) => escapeHtml(x ?? "");
|
|
1406
|
+
const base = a ? escapeHtml(annImage(a)) : "";
|
|
1407
|
+
const hasImg = !!(a && (a.image_file_id || a.image_url));
|
|
1408
|
+
return `<form id="ann-form" novalidate aria-labelledby="ann-form-title" class="glass-lite mb-4 rounded-2xl p-4">
|
|
1409
|
+
<h3 id="ann-form-title" class="text-[16px] font-semibold">${a ? "Edit announcement" : "New announcement"}</h3>
|
|
1410
|
+
<div class="mt-4 space-y-4">
|
|
1411
|
+
<div>
|
|
1412
|
+
<label for="af-title" class="text-[13px] font-medium text-ink-200">Title</label>
|
|
1413
|
+
<input id="af-title" maxlength="120" autocomplete="off" aria-describedby="af-title-err" value="${v(a?.title)}" class="field mt-1.5" />
|
|
1414
|
+
<p id="af-title-err" role="alert" class="mt-1.5 hidden text-[13px] text-red-300"></p>
|
|
1415
|
+
</div>
|
|
1416
|
+
<div>
|
|
1417
|
+
<label for="af-content" class="text-[13px] font-medium text-ink-200">Message <span class="font-normal text-ink-300">(optional)</span></label>
|
|
1418
|
+
<textarea id="af-content" rows="4" maxlength="2000" class="field mt-1.5 min-h-[104px] py-2.5 leading-relaxed" style="height:auto">${v(a?.content)}</textarea>
|
|
1419
|
+
</div>
|
|
1420
|
+
<fieldset class="min-w-0">
|
|
1421
|
+
<legend class="text-[13px] font-medium text-ink-200">Image <span class="font-normal text-ink-300">(optional)</span></legend>
|
|
1422
|
+
<img id="af-preview" src="${base}" data-base="${base}" alt="Image preview" ${base ? "" : "hidden"} class="mt-2 aspect-[16/9] w-full max-w-sm rounded-xl object-cover" onerror="this.hidden=true" />
|
|
1423
|
+
<div class="mt-3 grid gap-3">
|
|
1424
|
+
<div>
|
|
1425
|
+
<label for="af-file" class="text-[13px] text-ink-300">Upload an image</label>
|
|
1426
|
+
<input id="af-file" type="file" accept="image/*" aria-describedby="af-file-err" class="mt-1.5 w-full text-[13px] text-ink-300 file:mr-3 file:rounded-full file:border-0 file:bg-white/10 file:px-3.5 file:py-1.5 file:text-[13px] file:font-medium file:text-ink-50" />
|
|
1427
|
+
<p id="af-file-err" role="alert" class="mt-1.5 hidden text-[13px] text-red-300"></p>
|
|
1428
|
+
</div>
|
|
1429
|
+
<div>
|
|
1430
|
+
<label for="af-imgurl" class="text-[13px] text-ink-300">…or paste an image link</label>
|
|
1431
|
+
<input id="af-imgurl" type="url" inputmode="url" autocomplete="off" spellcheck="false" placeholder="https://" aria-describedby="af-imgurl-err" value="${v(a?.image_url)}" class="field mt-1.5" />
|
|
1432
|
+
<p id="af-imgurl-err" role="alert" class="mt-1.5 hidden text-[13px] text-red-300"></p>
|
|
1433
|
+
</div>
|
|
1434
|
+
${hasImg ? `<label class="flex items-center gap-2 text-[13px] text-ink-200"><input id="af-remove" type="checkbox" class="h-4 w-4 accent-red-500" /> Remove the current image</label>` : ""}
|
|
1435
|
+
</div>
|
|
1436
|
+
</fieldset>
|
|
1437
|
+
<label class="flex cursor-pointer items-center gap-3 text-[14px]"><input id="af-enabled" type="checkbox" role="switch" class="switch" ${a?.enabled === false ? "" : "checked"} /> Published (visible to visitors)</label>
|
|
1438
|
+
</div>
|
|
1439
|
+
<div class="mt-5 flex flex-wrap items-center gap-2">
|
|
1440
|
+
<button type="submit" id="af-submit" class="btn btn-primary">${a ? "Save changes" : "Publish"}</button>
|
|
1441
|
+
<button type="button" data-aact="cancel-form" class="btn btn-ghost">Cancel</button>
|
|
1442
|
+
</div>
|
|
1443
|
+
</form>`;
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
function annRowHtml(a) {
|
|
1447
|
+
if (annEditing === a.id) return `<li>${annFormHtml(a)}</li>`;
|
|
1448
|
+
const n = escapeHtml(a.title), off = a.enabled === false, dis = annEditing ? "disabled" : "";
|
|
1449
|
+
const snippet = escapeHtml((a.content || "").replace(/\s+/g, " ").slice(0, 70));
|
|
1450
|
+
const actions = annConfirming === a.id
|
|
1451
|
+
? `<div role="group" aria-label="Confirm delete" class="mt-3 rounded-xl bg-red-500/10 p-3 ring-1 ring-red-500/30">
|
|
1452
|
+
<p class="text-[14px]">Delete <strong>${n}</strong>? This can't be undone.</p>
|
|
1453
|
+
<div class="mt-3 flex gap-2">
|
|
1454
|
+
<button type="button" id="ann-cancel-delete" data-aact="cancel-delete" data-id="${a.id}" class="btn btn-ghost">Cancel</button>
|
|
1455
|
+
<button type="button" data-aact="confirm-delete" data-id="${a.id}" class="btn btn-danger">Delete</button>
|
|
1456
|
+
</div>
|
|
1457
|
+
</div>`
|
|
1458
|
+
: `<div class="mt-3 flex flex-wrap items-center gap-2">
|
|
1459
|
+
<button type="button" data-aact="edit" data-id="${a.id}" ${dis} class="btn btn-ghost">Edit${sr(" " + a.title)}</button>
|
|
1460
|
+
<button type="button" data-aact="delete" data-id="${a.id}" ${dis} class="btn btn-ghost ml-auto hover:!text-red-300">Delete${sr(" " + a.title)}</button>
|
|
1461
|
+
</div>`;
|
|
1462
|
+
return `<li class="glass-lite rounded-2xl p-3">
|
|
1463
|
+
<div class="flex items-center gap-3">
|
|
1464
|
+
<div class="min-w-0 flex-1">
|
|
1465
|
+
<p class="truncate text-[15px] font-medium">${n}${off ? '<span class="tag">Draft</span>' : ""}</p>
|
|
1466
|
+
<p class="truncate text-[13px] text-ink-300">${escapeHtml(fmtDate(a.created_at))}${snippet ? " · " + snippet : ""}</p>
|
|
1467
|
+
</div>
|
|
1468
|
+
<label class="flex shrink-0 cursor-pointer items-center gap-2 text-[13px] text-ink-200">
|
|
1469
|
+
<input type="checkbox" role="switch" class="switch" data-atoggle="${a.id}" ${off ? "" : "checked"} ${dis} />
|
|
1470
|
+
<span>Published${sr(": " + a.title)}</span>
|
|
1471
|
+
</label>
|
|
1472
|
+
</div>
|
|
1473
|
+
${actions}
|
|
1474
|
+
</li>`;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
function renderAnnAdmin(focusSels = []) {
|
|
1478
|
+
dirty.ann = false;
|
|
1479
|
+
const list = el("ann-admin-list");
|
|
1480
|
+
el("ann-form-slot").innerHTML = annEditing === "new" ? annFormHtml(null) : "";
|
|
1481
|
+
el("ann-add").disabled = !!annEditing || annState !== "ready";
|
|
1482
|
+
if (annState === "unconfigured") {
|
|
1483
|
+
setSummary("ann", "Not set up yet");
|
|
1484
|
+
list.innerHTML = `<li class="glass-lite rounded-2xl p-4 text-[14px] leading-relaxed text-ink-200">
|
|
1485
|
+
<p class="font-semibold text-ink-50">One-time setup</p>
|
|
1486
|
+
<p class="mt-2">Announcements need their <code class="text-ink-50">announcements</code> table. Run <code class="text-ink-50">supabase-setup.sql</code> in the Supabase SQL Editor — it creates the table with the right columns.</p>
|
|
1487
|
+
<p class="mt-2">Then make sure <code class="text-ink-50">CONFIG</code> at the bottom of this file points at your Supabase project (URL + anon key).</p>
|
|
1488
|
+
</li>`;
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
if (annState === "loading") { setSummary("ann", ""); list.innerHTML = `<li class="py-8 text-center text-[14px] text-ink-300">Loading announcements…</li>`; return; }
|
|
1492
|
+
if (annState === "error") {
|
|
1493
|
+
setSummary("ann", "");
|
|
1494
|
+
list.innerHTML = `<li class="py-8 text-center"><p class="text-[14px] text-red-300">${escapeHtml(annError)}</p><button type="button" data-aact="retry" class="btn btn-ghost mt-3">Try again</button></li>`;
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
const pub = annRows.filter((a) => a.enabled !== false).length;
|
|
1498
|
+
setSummary("ann", `${annRows.length} ${annRows.length === 1 ? "announcement" : "announcements"} · ${pub} published`);
|
|
1499
|
+
list.innerHTML = annRows.length ? annRows.map(annRowHtml).join("") : `<li class="py-8 text-center text-[14px] text-ink-300">No announcements yet. Choose “New announcement” to post one.</li>`;
|
|
1500
|
+
if (annEditing) { const n = el("af-title"); n.focus(); n.scrollIntoView({ block: "nearest" }); return; }
|
|
1501
|
+
for (const sel of focusSels) {
|
|
1502
|
+
const t = el("admin-panel-card").querySelector(sel);
|
|
1503
|
+
if (t && !t.disabled) { t.focus(); break; }
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
function cancelAnnForm() {
|
|
1507
|
+
const id = annEditing;
|
|
1508
|
+
annEditing = null;
|
|
1509
|
+
renderAnnAdmin([id && id !== "new" ? `[data-aact="edit"][data-id="${id}"]` : "#ann-add"]);
|
|
1510
|
+
}
|
|
1511
|
+
function updateAnnPreview() {
|
|
1512
|
+
const img = el("af-preview"), file = el("af-file").files[0], url = el("af-imgurl").value.trim();
|
|
1513
|
+
if (annPreviewUrl) { URL.revokeObjectURL(annPreviewUrl); annPreviewUrl = null; }
|
|
1514
|
+
let src = img.dataset.base || "";
|
|
1515
|
+
if (el("af-remove")?.checked) src = "";
|
|
1516
|
+
else if (file && file.type.startsWith("image/")) src = annPreviewUrl = URL.createObjectURL(file);
|
|
1517
|
+
else if (isHttp(url)) src = url;
|
|
1518
|
+
img.hidden = !src;
|
|
1519
|
+
if (src) img.src = src;
|
|
1520
|
+
}
|
|
1521
|
+
function validateAnnForm() {
|
|
1522
|
+
const url = el("af-imgurl").value.trim(), f = el("af-file").files[0];
|
|
1523
|
+
const checks = [
|
|
1524
|
+
["af-title", el("af-title").value.trim() ? "" : "Enter a title."],
|
|
1525
|
+
["af-imgurl", !url || isHttp(url) ? "" : "Enter a full link that starts with https://"],
|
|
1526
|
+
["af-file", !f || f.type.startsWith("image/") ? "" : "Choose an image file."],
|
|
1527
|
+
];
|
|
1528
|
+
let first = null;
|
|
1529
|
+
checks.forEach(([id, msg]) => { setErr(id, msg); if (msg && !first) first = id; });
|
|
1530
|
+
if (first) el(first).focus();
|
|
1531
|
+
return !first;
|
|
1532
|
+
}
|
|
1533
|
+
async function submitAnn(e) {
|
|
1534
|
+
e.preventDefault();
|
|
1535
|
+
if (!validateAnnForm()) return;
|
|
1536
|
+
const isEdit = annEditing && annEditing !== "new";
|
|
1537
|
+
const existing = isEdit ? annRows.find((r) => r.id === annEditing) : null;
|
|
1538
|
+
const title = el("af-title").value.trim(), content = el("af-content").value.trim(), urlField = el("af-imgurl").value.trim();
|
|
1539
|
+
const file = el("af-file").files[0], enabled = el("af-enabled").checked, remove = !!el("af-remove")?.checked;
|
|
1540
|
+
const btn = el("af-submit"), label = btn.textContent;
|
|
1541
|
+
btn.disabled = true; btn.textContent = "Saving…";
|
|
1542
|
+
let uploadedPath = null, oldFile = null;
|
|
1543
|
+
try {
|
|
1544
|
+
let image_file_id = existing?.image_file_id || "", image_url = existing?.image_url || "";
|
|
1545
|
+
if (remove) { oldFile = image_file_id; image_file_id = ""; image_url = ""; }
|
|
1546
|
+
else if (file) {
|
|
1547
|
+
uploadedPath = (await unwrap(sb.storage.from(CONFIG.iconsBucket).upload(crypto.randomUUID(), file))).path;
|
|
1548
|
+
oldFile = image_file_id; image_file_id = uploadedPath; image_url = "";
|
|
1549
|
+
} else if (urlField && urlField !== image_url) { oldFile = image_file_id; image_file_id = ""; image_url = urlField; }
|
|
1550
|
+
else if (!urlField && image_url && !image_file_id) image_url = "";
|
|
1551
|
+
const data = { title, content, image_file_id, image_url, enabled };
|
|
1552
|
+
let row;
|
|
1553
|
+
if (isEdit) {
|
|
1554
|
+
row = await unwrap(sb.from(CONFIG.announcementsTable).update(data).eq("id", annEditing).select().single());
|
|
1555
|
+
annRows = annRows.map((r) => (r.id === row.id ? row : r));
|
|
1556
|
+
} else {
|
|
1557
|
+
row = await unwrap(sb.from(CONFIG.announcementsTable).insert(data).select().single());
|
|
1558
|
+
annRows = [row, ...annRows];
|
|
1559
|
+
}
|
|
1560
|
+
if (oldFile) sb.storage.from(CONFIG.iconsBucket).remove([oldFile]).catch(() => {});
|
|
1561
|
+
annEditing = null;
|
|
1562
|
+
renderAnnAdmin([`[data-aact="edit"][data-id="${row.id}"]`]);
|
|
1563
|
+
toast(isEdit ? `Saved “${title}”` : `Posted “${title}”`);
|
|
1564
|
+
loadAnnouncements();
|
|
1565
|
+
} catch (err) {
|
|
1566
|
+
if (uploadedPath) sb.storage.from(CONFIG.iconsBucket).remove([uploadedPath]).catch(() => {});
|
|
1567
|
+
btn.disabled = false; btn.textContent = label;
|
|
1568
|
+
toast(err?.message || "Couldn't save. Check your connection and try again.", "error");
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
async function toggleAnn(id, on) {
|
|
1572
|
+
const row = annRows.find((r) => r.id === id);
|
|
1573
|
+
if (!row) return;
|
|
1574
|
+
const prev = row.enabled !== false;
|
|
1575
|
+
row.enabled = on;
|
|
1576
|
+
renderAnnAdmin([`[data-atoggle="${id}"]`]);
|
|
1577
|
+
try {
|
|
1578
|
+
await unwrap(sb.from(CONFIG.announcementsTable).update({ enabled: on }).eq("id", id));
|
|
1579
|
+
adminSay(`${row.title} is now ${on ? "published" : "a draft"}`);
|
|
1580
|
+
loadAnnouncements();
|
|
1581
|
+
} catch (err) {
|
|
1582
|
+
row.enabled = prev;
|
|
1583
|
+
renderAnnAdmin([`[data-atoggle="${id}"]`]);
|
|
1584
|
+
toast(err?.message || "Couldn't update", "error");
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
async function deleteAnn(id) {
|
|
1588
|
+
const row = annRows.find((r) => r.id === id);
|
|
1589
|
+
if (!row) return;
|
|
1590
|
+
try {
|
|
1591
|
+
await unwrap(sb.from(CONFIG.announcementsTable).delete().eq("id", id));
|
|
1592
|
+
if (row.image_file_id) sb.storage.from(CONFIG.iconsBucket).remove([row.image_file_id]).catch(() => {});
|
|
1593
|
+
annRows = annRows.filter((r) => r.id !== id);
|
|
1594
|
+
annConfirming = null;
|
|
1595
|
+
renderAnnAdmin(["#ann-add"]);
|
|
1596
|
+
toast(`Deleted “${row.title}”`);
|
|
1597
|
+
loadAnnouncements();
|
|
1598
|
+
} catch (err) {
|
|
1599
|
+
renderAnnAdmin(["#ann-cancel-delete"]);
|
|
1600
|
+
toast(err?.message || "Couldn't delete. Try again.", "error");
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
el("ann-add").addEventListener("click", () => { annEditing = "new"; annConfirming = null; renderAnnAdmin(); });
|
|
1604
|
+
el("ann-admin-body").addEventListener("click", (e) => {
|
|
1605
|
+
const b = e.target.closest("[data-aact]");
|
|
1606
|
+
if (!b || b.disabled) return;
|
|
1607
|
+
const { aact, id } = b.dataset;
|
|
1608
|
+
if (aact === "retry") loadAnnAdmin();
|
|
1609
|
+
else if (aact === "edit") { annEditing = id; annConfirming = null; renderAnnAdmin(); }
|
|
1610
|
+
else if (aact === "cancel-form") cancelAnnForm();
|
|
1611
|
+
else if (aact === "delete") { annConfirming = id; renderAnnAdmin(["#ann-cancel-delete"]); }
|
|
1612
|
+
else if (aact === "cancel-delete") { annConfirming = null; renderAnnAdmin([`[data-aact="delete"][data-id="${id}"]`]); }
|
|
1613
|
+
else if (aact === "confirm-delete") { b.disabled = true; b.textContent = "Deleting…"; deleteAnn(id); }
|
|
1614
|
+
});
|
|
1615
|
+
el("ann-admin-body").addEventListener("change", (e) => {
|
|
1616
|
+
const t = e.target;
|
|
1617
|
+
if (t.matches("[data-atoggle]")) toggleAnn(t.dataset.atoggle, t.checked);
|
|
1618
|
+
else if (t.id === "af-file" || t.id === "af-remove") updateAnnPreview();
|
|
1619
|
+
});
|
|
1620
|
+
el("ann-admin-body").addEventListener("input", (e) => {
|
|
1621
|
+
const t = e.target;
|
|
1622
|
+
if (t.getAttribute?.("aria-invalid")) setErr(t.id, "");
|
|
1623
|
+
if (t.id === "af-imgurl") updateAnnPreview();
|
|
1624
|
+
});
|
|
1625
|
+
el("ann-admin-body").addEventListener("submit", (e) => { if (e.target.id === "ann-form") submitAnn(e); });
|
|
1626
|
+
|
|
1627
|
+
/* ============================ settings: apply ============================ */
|
|
1628
|
+
const origTitle = document.title;
|
|
1629
|
+
const origIcon = document.querySelector('link[rel~="icon"]')?.href || "";
|
|
1630
|
+
function setFavicon(href) {
|
|
1631
|
+
document.head.querySelectorAll('link[rel~="icon"]').forEach((l) => l.remove());
|
|
1632
|
+
const l = document.createElement("link");
|
|
1633
|
+
l.rel = "icon"; l.href = href;
|
|
1634
|
+
document.head.appendChild(l);
|
|
1635
|
+
}
|
|
1636
|
+
function applyCloak() {
|
|
1637
|
+
const c = settings.cloak;
|
|
1638
|
+
let title = origTitle, icon = origIcon;
|
|
1639
|
+
if (c === "custom") { if (settings.customTitle) title = settings.customTitle; if (isHttp(settings.customIcon)) icon = settings.customIcon; }
|
|
1640
|
+
else if (c !== "off") { title = CLOAKS[c].title; icon = CLOAKS[c].icon; }
|
|
1641
|
+
document.title = title;
|
|
1642
|
+
setFavicon(icon);
|
|
1643
|
+
}
|
|
1644
|
+
function applyMotion() {
|
|
1645
|
+
reduceMotion = sysReduce || settings.reduceMotion;
|
|
1646
|
+
document.documentElement.classList.toggle("rm", reduceMotion);
|
|
1647
|
+
}
|
|
1648
|
+
function applyTileSize() {
|
|
1649
|
+
for (const g of [el("grid"), el("skeleton-grid")]) {
|
|
1650
|
+
Object.values(SIZES).forEach((c) => g.classList.remove(...c.split(" ")));
|
|
1651
|
+
g.classList.add(...SIZES[settings.tileSize].split(" "));
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
// "Mask text": swap letters for look-alike characters in everything on the page (not in the admin/settings dialogs).
|
|
1656
|
+
const MASK = { a: "\u0430", c: "\u0441", e: "\u0435", i: "\u0456", j: "\u0458", o: "\u043E", p: "\u0440", s: "\u0455", x: "\u0445", y: "\u0443",
|
|
1657
|
+
A: "\u0410", B: "\u0412", C: "\u0421", E: "\u0415", H: "\u041D", I: "\u0406", J: "\u0408", K: "\u041A", M: "\u041C", O: "\u041E", P: "\u0420", S: "\u0405", T: "\u0422", X: "\u0425", Y: "\u04AE" };
|
|
1658
|
+
const maskStr = (t) => t.replace(/[acejiopsxyABCEHIJKMOPSTXY]/g, (c) => MASK[c]);
|
|
1659
|
+
const maskOrig = new WeakMap();
|
|
1660
|
+
function maskNode(n) {
|
|
1661
|
+
if (n.nodeType !== 3 || !n.nodeValue.trim() || n.parentElement?.closest("script,style,textarea,[data-nomask]")) return;
|
|
1662
|
+
if (!maskOrig.has(n)) maskOrig.set(n, n.nodeValue);
|
|
1663
|
+
n.nodeValue = maskStr(maskOrig.get(n));
|
|
1664
|
+
}
|
|
1665
|
+
function walkText(root, fn) {
|
|
1666
|
+
const w = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
1667
|
+
let n;
|
|
1668
|
+
while ((n = w.nextNode())) fn(n);
|
|
1669
|
+
}
|
|
1670
|
+
let maskObs = null;
|
|
1671
|
+
function setMask(on) {
|
|
1672
|
+
maskObs?.disconnect();
|
|
1673
|
+
maskObs = null;
|
|
1674
|
+
if (on) {
|
|
1675
|
+
walkText(document.body, maskNode);
|
|
1676
|
+
maskObs = new MutationObserver((muts) => muts.forEach((m) => m.addedNodes.forEach((n) => (n.nodeType === 3 ? maskNode(n) : n.nodeType === 1 && walkText(n, maskNode)))));
|
|
1677
|
+
maskObs.observe(document.body, { childList: true, subtree: true });
|
|
1678
|
+
} else walkText(document.body, (n) => { if (maskOrig.has(n)) { n.nodeValue = maskOrig.get(n); maskOrig.delete(n); } });
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
/* ============================ panic button + safety ============================ */
|
|
1682
|
+
let panicking = false, capturingKey = false;
|
|
1683
|
+
function comboOf(e) {
|
|
1684
|
+
const k = e.key;
|
|
1685
|
+
if (["Control", "Shift", "Alt", "Meta"].includes(k)) return "";
|
|
1686
|
+
const parts = [];
|
|
1687
|
+
if (e.ctrlKey) parts.push("Ctrl");
|
|
1688
|
+
if (e.altKey) parts.push("Alt");
|
|
1689
|
+
if (e.metaKey) parts.push("Meta");
|
|
1690
|
+
if (e.shiftKey && k.length > 1) parts.push("Shift");
|
|
1691
|
+
parts.push(k.length === 1 ? k.toUpperCase() : k);
|
|
1692
|
+
return parts.join("+");
|
|
1693
|
+
}
|
|
1694
|
+
const showCombo = (c) => c.replace(/(^|\+) $/, "$1Space");
|
|
1695
|
+
function panic() {
|
|
1696
|
+
panicking = true;
|
|
1697
|
+
document.documentElement.style.visibility = "hidden";
|
|
1698
|
+
location.replace(isHttp(settings.panic.url) ? settings.panic.url : DEFAULTS.panic.url);
|
|
1699
|
+
setTimeout(() => { document.documentElement.style.visibility = ""; panicking = false; }, 3000); // restore if the navigation was blocked
|
|
1700
|
+
}
|
|
1701
|
+
function updatePanicUI() {
|
|
1702
|
+
const on = settings.panic.enabled && settings.panic.button;
|
|
1703
|
+
el("panic-btn").hidden = !on;
|
|
1704
|
+
el("player-panic").hidden = !on;
|
|
1705
|
+
el("panic-key").textContent = showCombo(settings.panic.key);
|
|
1706
|
+
}
|
|
1707
|
+
document.addEventListener("keydown", (e) => {
|
|
1708
|
+
if (capturingKey) {
|
|
1709
|
+
const c = comboOf(e);
|
|
1710
|
+
if (!c) return;
|
|
1711
|
+
e.preventDefault(); e.stopPropagation();
|
|
1712
|
+
capturingKey = false;
|
|
1713
|
+
if (e.key !== "Escape") { settings.panic.key = c; saveSettings(); }
|
|
1714
|
+
updatePanicUI();
|
|
1715
|
+
el("panic-key").focus();
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
const p = settings.panic;
|
|
1719
|
+
if (!p.enabled || e.repeat || comboOf(e) !== p.key) return;
|
|
1720
|
+
const typing = e.target.matches?.("input, textarea, select, [contenteditable]");
|
|
1721
|
+
if (typing && !(e.ctrlKey || e.altKey || e.metaKey) && e.key.length === 1) return;
|
|
1722
|
+
e.preventDefault();
|
|
1723
|
+
panic();
|
|
1724
|
+
}, true);
|
|
1725
|
+
el("panic-btn").addEventListener("click", panic);
|
|
1726
|
+
el("player-panic").addEventListener("click", panic);
|
|
1727
|
+
addEventListener("beforeunload", (e) => { if (settings.confirmClose && !panicking) { e.preventDefault(); e.returnValue = ""; } });
|
|
1728
|
+
|
|
1729
|
+
function launchBlank() {
|
|
1730
|
+
const w = window.open("about:blank", "_blank");
|
|
1731
|
+
if (!w) { toast("Your browser blocked the new tab. Allow pop-ups for this site and try again.", "error"); return; }
|
|
1732
|
+
const d = w.document;
|
|
1733
|
+
d.title = document.title;
|
|
1734
|
+
d.body.style.cssText = "margin:0;background:#000";
|
|
1735
|
+
const f = d.createElement("iframe");
|
|
1736
|
+
f.src = location.href;
|
|
1737
|
+
f.style.cssText = "position:fixed;inset:0;width:100%;height:100%;border:0";
|
|
1738
|
+
f.allow = "autoplay; fullscreen; gamepad";
|
|
1739
|
+
d.body.appendChild(f);
|
|
1740
|
+
panic();
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
/* ============================ settings: dialog ============================ */
|
|
1744
|
+
const selectSettingsTab = wireTabs(el("settings-tabs"));
|
|
1745
|
+
function renderCloakOptions() {
|
|
1746
|
+
el("cloak-options").innerHTML = Object.entries(CLOAKS).map(([k, c]) =>
|
|
1747
|
+
`<label class="opt"><input type="radio" name="cloak" value="${k}" class="sr-only" /><img src="${escapeHtml(c.icon || origIcon)}" alt="" class="h-8 w-8 shrink-0 rounded-lg bg-white/10" />
|
|
1748
|
+
<span class="min-w-0"><span class="block text-[15px] font-medium">${escapeHtml(c.label)}</span><span class="block truncate text-[13px] text-ink-300">${escapeHtml(c.sub)}</span></span></label>`).join("");
|
|
1749
|
+
}
|
|
1750
|
+
function syncSettingsUI() {
|
|
1751
|
+
el("set-announce").checked = settings.announceOnOpen;
|
|
1752
|
+
el("set-reduce").checked = settings.reduceMotion;
|
|
1753
|
+
document.querySelector(`input[name="tile"][value="${settings.tileSize}"]`).checked = true;
|
|
1754
|
+
document.querySelector(`input[name="cloak"][value="${settings.cloak}"]`).checked = true;
|
|
1755
|
+
el("custom-cloak").hidden = settings.cloak !== "custom";
|
|
1756
|
+
el("cc-title").value = settings.customTitle;
|
|
1757
|
+
el("cc-icon").value = settings.customIcon;
|
|
1758
|
+
el("panic-on").checked = settings.panic.enabled;
|
|
1759
|
+
el("panic-url").value = settings.panic.url;
|
|
1760
|
+
el("panic-btn-on").checked = settings.panic.button;
|
|
1761
|
+
el("set-mask").checked = settings.maskText;
|
|
1762
|
+
el("set-confirm").checked = settings.confirmClose;
|
|
1763
|
+
updatePanicUI();
|
|
1764
|
+
}
|
|
1765
|
+
function applyAllSettings() { applyMotion(); applyTileSize(); applyCloak(); setMask(settings.maskText); updatePanicUI(); }
|
|
1766
|
+
function refreshLib() {
|
|
1767
|
+
const ok = isUnlocked();
|
|
1768
|
+
el("export-games").disabled = !ok;
|
|
1769
|
+
el("import-games-btn").disabled = !ok;
|
|
1770
|
+
el("lib-lock").hidden = ok;
|
|
1771
|
+
el("unlock-admin").hidden = ok;
|
|
1772
|
+
}
|
|
1773
|
+
function openSettings() { syncSettingsUI(); refreshLib(); openModal("settings-modal", "settings-card", "settings-title"); }
|
|
1774
|
+
function closeSettings() { closeModal("settings-modal"); }
|
|
1775
|
+
el("settings-btn").addEventListener("click", openSettings);
|
|
1776
|
+
el("settings-close").addEventListener("click", closeSettings);
|
|
1777
|
+
el("open-admin").addEventListener("click", () => { closeSettings(); if (isUnlocked()) openAdminPanel(); else openAdminLogin(); });
|
|
1778
|
+
el("unlock-admin").addEventListener("click", () => { closeSettings(); openAdminLogin(); });
|
|
1779
|
+
|
|
1780
|
+
const on = (id, evt, fn) => el(id).addEventListener(evt, fn);
|
|
1781
|
+
on("set-announce", "change", (e) => { settings.announceOnOpen = e.target.checked; saveSettings(); });
|
|
1782
|
+
on("set-reduce", "change", (e) => { settings.reduceMotion = e.target.checked; saveSettings(); applyMotion(); });
|
|
1783
|
+
document.querySelectorAll('input[name="tile"]').forEach((r) => r.addEventListener("change", () => { settings.tileSize = r.value; saveSettings(); applyTileSize(); }));
|
|
1784
|
+
on("cloak-options", "change", (e) => {
|
|
1785
|
+
settings.cloak = e.target.value; saveSettings(); applyCloak();
|
|
1786
|
+
el("custom-cloak").hidden = settings.cloak !== "custom";
|
|
1787
|
+
if (settings.cloak === "custom") focusSoon(el("cc-title"));
|
|
1788
|
+
});
|
|
1789
|
+
on("cc-title", "input", (e) => { settings.customTitle = e.target.value; saveSettings(); applyCloak(); });
|
|
1790
|
+
on("cc-icon", "input", (e) => { settings.customIcon = e.target.value.trim(); saveSettings(); applyCloak(); });
|
|
1791
|
+
on("panic-on", "change", (e) => { settings.panic.enabled = e.target.checked; saveSettings(); updatePanicUI(); });
|
|
1792
|
+
on("panic-btn-on", "change", (e) => { settings.panic.button = e.target.checked; saveSettings(); updatePanicUI(); });
|
|
1793
|
+
on("panic-key", "click", () => { capturingKey = true; el("panic-key").textContent = "Press a key…"; });
|
|
1794
|
+
on("panic-key", "blur", () => { if (capturingKey) { capturingKey = false; updatePanicUI(); } });
|
|
1795
|
+
on("panic-url", "input", (e) => {
|
|
1796
|
+
const v = e.target.value.trim(), err = el("panic-url-err");
|
|
1797
|
+
const bad = v && !isHttp(v);
|
|
1798
|
+
err.textContent = bad ? "Enter a full link that starts with https://" : "";
|
|
1799
|
+
err.classList.toggle("hidden", !bad);
|
|
1800
|
+
e.target.toggleAttribute("aria-invalid", !!bad);
|
|
1801
|
+
if (!bad) { settings.panic.url = v || DEFAULTS.panic.url; saveSettings(); }
|
|
1802
|
+
});
|
|
1803
|
+
on("set-mask", "change", (e) => { settings.maskText = e.target.checked; saveSettings(); setMask(settings.maskText); });
|
|
1804
|
+
on("set-confirm", "change", (e) => { settings.confirmClose = e.target.checked; saveSettings(); });
|
|
1805
|
+
on("launch-blank", "click", launchBlank);
|
|
1806
|
+
|
|
1807
|
+
/* ============================ settings: data ============================ */
|
|
1808
|
+
function download(name, obj) {
|
|
1809
|
+
const a = document.createElement("a");
|
|
1810
|
+
a.href = URL.createObjectURL(new Blob([JSON.stringify(obj, null, 2)], { type: "application/json" }));
|
|
1811
|
+
a.download = name;
|
|
1812
|
+
document.body.appendChild(a);
|
|
1813
|
+
a.click();
|
|
1814
|
+
a.remove();
|
|
1815
|
+
setTimeout(() => URL.revokeObjectURL(a.href), 2000);
|
|
1816
|
+
}
|
|
1817
|
+
const libStatus = (t) => { el("lib-status").textContent = t; };
|
|
1818
|
+
let resetTimer = null, pendingImport = null;
|
|
1819
|
+
on("export-settings", "click", () => { download("mlv2-settings.json", { app: "mlv2", type: "settings", version: 1, settings }); toast("Settings exported"); });
|
|
1820
|
+
on("import-settings-btn", "click", () => el("import-settings").click());
|
|
1821
|
+
on("import-settings", "change", async (e) => {
|
|
1822
|
+
const f = e.target.files[0];
|
|
1823
|
+
e.target.value = "";
|
|
1824
|
+
if (!f) return;
|
|
1825
|
+
try {
|
|
1826
|
+
const data = JSON.parse(await f.text());
|
|
1827
|
+
if (data?.type !== "settings" || typeof data.settings !== "object") throw new Error("bad");
|
|
1828
|
+
settings = mergeSettings(DEFAULTS, data.settings);
|
|
1829
|
+
saveSettings(); applyAllSettings(); syncSettingsUI();
|
|
1830
|
+
toast("Settings imported");
|
|
1831
|
+
} catch { toast("That doesn't look like a settings file.", "error"); }
|
|
1832
|
+
});
|
|
1833
|
+
on("reset-seen", "click", () => { try { localStorage.removeItem(SEEN_KEY); } catch { /* storage blocked */ } refreshBell(); toast("You'll see announcements again"); });
|
|
1834
|
+
on("reset-settings", "click", (e) => {
|
|
1835
|
+
const b = e.currentTarget;
|
|
1836
|
+
if (b.dataset.armed) {
|
|
1837
|
+
clearTimeout(resetTimer); delete b.dataset.armed; b.textContent = "Reset";
|
|
1838
|
+
settings = mergeSettings(DEFAULTS, null);
|
|
1839
|
+
saveSettings(); applyAllSettings(); syncSettingsUI();
|
|
1840
|
+
toast("Settings reset");
|
|
1841
|
+
} else {
|
|
1842
|
+
b.dataset.armed = "1"; b.textContent = "Click again to confirm";
|
|
1843
|
+
resetTimer = setTimeout(() => { delete b.dataset.armed; b.textContent = "Reset"; }, 4000);
|
|
1844
|
+
}
|
|
1845
|
+
});
|
|
1846
|
+
|
|
1847
|
+
async function fetchAllGames() {
|
|
1848
|
+
const rows = await unwrap(sb.from(CONFIG.gamesTable).select("*").order("sort_order").limit(200));
|
|
1849
|
+
return rows.slice().sort(byOrder);
|
|
1850
|
+
}
|
|
1851
|
+
on("export-games", "click", async () => {
|
|
1852
|
+
if (!isUnlocked()) return refreshLib();
|
|
1853
|
+
libStatus("Preparing export…");
|
|
1854
|
+
try {
|
|
1855
|
+
const rows = await fetchAllGames();
|
|
1856
|
+
const games = rows.map((g) => ({ name: g.name, url: g.url, category: g.category || "", iconUrl: g.icon_file_id ? String(iconSrcFor(g) || "") : g.icon_url || "", enabled: g.enabled !== false }));
|
|
1857
|
+
download("mlv2-games.json", { app: "mlv2", type: "games", version: 1, exportedAt: new Date().toISOString(), games });
|
|
1858
|
+
libStatus(`Exported ${games.length} ${games.length === 1 ? "game" : "games"}.`);
|
|
1859
|
+
} catch (err) { libStatus(err?.message || "Couldn't export your games."); }
|
|
1860
|
+
});
|
|
1861
|
+
on("import-games-btn", "click", () => el("import-games").click());
|
|
1862
|
+
on("import-games", "change", async (e) => {
|
|
1863
|
+
const f = e.target.files[0], go = el("import-games-go");
|
|
1864
|
+
e.target.value = "";
|
|
1865
|
+
if (!f || !isUnlocked()) return;
|
|
1866
|
+
go.hidden = true; pendingImport = null;
|
|
1867
|
+
try {
|
|
1868
|
+
const data = JSON.parse(await f.text());
|
|
1869
|
+
if (data?.type !== "games" || !Array.isArray(data.games)) throw new Error("That file isn't an mlv2 games export.");
|
|
1870
|
+
const existing = await fetchAllGames();
|
|
1871
|
+
const have = new Set(existing.map((g) => g.url));
|
|
1872
|
+
const valid = data.games.filter((g) => g && typeof g.name === "string" && g.name.trim() && isHttp(g.url));
|
|
1873
|
+
const fresh = valid.filter((g, i, a) => !have.has(g.url) && a.findIndex((x) => x.url === g.url) === i);
|
|
1874
|
+
pendingImport = { fresh, base: existing.reduce((m, r) => Math.max(m, r.sort_order ?? -1), -1) + 1 };
|
|
1875
|
+
libStatus(`Found ${valid.length} valid games. ${fresh.length} ${fresh.length === 1 ? "is" : "are"} new; the rest are already in your library.`);
|
|
1876
|
+
if (fresh.length) { go.textContent = `Import ${fresh.length} new ${fresh.length === 1 ? "game" : "games"}`; go.hidden = false; }
|
|
1877
|
+
} catch (err) { libStatus(err?.message || "Couldn't read that file."); }
|
|
1878
|
+
});
|
|
1879
|
+
on("import-games-go", "click", async (e) => {
|
|
1880
|
+
const go = e.currentTarget;
|
|
1881
|
+
if (!pendingImport || !isUnlocked()) return;
|
|
1882
|
+
const { fresh, base } = pendingImport;
|
|
1883
|
+
go.disabled = true;
|
|
1884
|
+
let done = 0, failed = 0;
|
|
1885
|
+
for (const [i, g] of fresh.entries()) {
|
|
1886
|
+
libStatus(`Importing ${i + 1} of ${fresh.length}…`);
|
|
1887
|
+
try {
|
|
1888
|
+
await unwrap(sb.from(CONFIG.gamesTable).insert({ name: g.name.trim(), url: g.url, category: String(g.category || "").trim(), icon_file_id: "", icon_url: isHttp(g.iconUrl) ? g.iconUrl : "", enabled: g.enabled !== false, sort_order: base + i }));
|
|
1889
|
+
done++;
|
|
1890
|
+
} catch { failed++; }
|
|
1891
|
+
}
|
|
1892
|
+
go.disabled = false; go.hidden = true; pendingImport = null;
|
|
1893
|
+
libStatus(`Imported ${done} ${done === 1 ? "game" : "games"}${failed ? `, ${failed} failed` : ""}.`);
|
|
1894
|
+
toast(failed ? `Imported ${done}, ${failed} failed` : `Imported ${done} ${done === 1 ? "game" : "games"}`, failed ? "error" : "default");
|
|
1895
|
+
loadGames();
|
|
1896
|
+
});
|
|
1897
|
+
|
|
1898
|
+
/* ============================ boot ============================ */
|
|
1899
|
+
renderCloakOptions();
|
|
1900
|
+
applyAllSettings();
|
|
1901
|
+
loadAnnouncements();
|
|
1902
|
+
|
|
1903
|
+
/* ---------------------------- tile hover FX ---------------------------- */
|
|
1904
|
+
const gridEl = el("grid");
|
|
1905
|
+
gridEl.addEventListener("pointermove", (e) => {
|
|
1906
|
+
if (e.pointerType !== "mouse" || reduceMotion) return;
|
|
1907
|
+
const t = e.target.closest(".tile");
|
|
1908
|
+
if (!t) return;
|
|
1909
|
+
const r = t.getBoundingClientRect();
|
|
1910
|
+
const x = (e.clientX - r.left) / r.width, y = (e.clientY - r.top) / r.height;
|
|
1911
|
+
t.classList.add("moving");
|
|
1912
|
+
t.style.setProperty("--mx", x * 100 + "%");
|
|
1913
|
+
t.style.setProperty("--my", y * 100 + "%");
|
|
1914
|
+
const icon = t.firstElementChild;
|
|
1915
|
+
icon.style.setProperty("--ry", ((x - 0.5) * 16).toFixed(2) + "deg");
|
|
1916
|
+
icon.style.setProperty("--rx", ((0.5 - y) * 16).toFixed(2) + "deg");
|
|
1917
|
+
});
|
|
1918
|
+
gridEl.addEventListener("pointerout", (e) => {
|
|
1919
|
+
const t = e.target.closest(".tile");
|
|
1920
|
+
if (!t || t.contains(e.relatedTarget)) return;
|
|
1921
|
+
t.classList.remove("moving");
|
|
1922
|
+
t.firstElementChild.style.removeProperty("--rx");
|
|
1923
|
+
t.firstElementChild.style.removeProperty("--ry");
|
|
1924
|
+
});
|
|
1925
|
+
|
|
1926
|
+
el("player-frame").addEventListener("load", () => {
|
|
1927
|
+
if (el("player-frame").getAttribute("src") !== "about:blank") el("player-loading").style.display = "none";
|
|
1928
|
+
});
|
|
1929
|
+
|
|
1930
|
+
/* ------------------------------ hero motion ------------------------------ */
|
|
1931
|
+
(function hero() {
|
|
1932
|
+
const show = () => document.querySelectorAll(".w, .shape").forEach((n) => (n.style.opacity = 1));
|
|
1933
|
+
if (reduceMotion) return show();
|
|
1934
|
+
animate(".w", { opacity: [0, 1], y: [32, 0], filter: ["blur(14px)", "blur(0px)"] },
|
|
1935
|
+
{ duration: 0.85, delay: stagger(0.08, { startDelay: 0.1 }), ease: [0.22, 1, 0.36, 1] })
|
|
1936
|
+
.finished.then(() => document.querySelectorAll(".w").forEach((w) => (w.style.filter = "none")));
|
|
1937
|
+
animate(".shape", { opacity: [0, 1] }, { duration: 0.4, delay: stagger(0.1, { startDelay: 0.4 }) });
|
|
1938
|
+
animate(".shape", { scale: [0.2, 1], rotate: [-40, 0] }, { type: "spring", stiffness: 170, damping: 13, delay: stagger(0.1, { startDelay: 0.4 }) });
|
|
1939
|
+
|
|
1940
|
+
// gentle cursor + scroll parallax on the shapes
|
|
1941
|
+
const pars = [...document.querySelectorAll(".par")];
|
|
1942
|
+
const wrap = el("shapes");
|
|
1943
|
+
let tx = 0, ty = 0, cx = 0, cy = 0;
|
|
1944
|
+
addEventListener("pointermove", (e) => { tx = e.clientX / innerWidth - 0.5; ty = e.clientY / innerHeight - 0.5; }, { passive: true });
|
|
1945
|
+
(function loop() {
|
|
1946
|
+
cx += (tx - cx) * 0.07;
|
|
1947
|
+
cy += (ty - cy) * 0.07;
|
|
1948
|
+
if (wrap.offsetParent) {
|
|
1949
|
+
pars.forEach((p) => {
|
|
1950
|
+
const d = Number(p.dataset.depth);
|
|
1951
|
+
p.style.transform = `translate3d(${(-cx * 36 * d).toFixed(2)}px, ${(-cy * 36 * d - scrollY * 0.12 * d).toFixed(2)}px, 0)`;
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
requestAnimationFrame(loop);
|
|
1955
|
+
})();
|
|
1956
|
+
})();
|
|
1957
|
+
</script>
|
|
1958
|
+
<script>
|
|
1959
|
+
// safety net: never leave the title or shapes invisible if the module script is blocked
|
|
1960
|
+
setTimeout(function () { document.querySelectorAll(".w, .shape").forEach(function (n) { if (getComputedStyle(n).opacity < 1) n.style.opacity = 1; }); }, 3500);
|
|
1961
|
+
</script>
|
|
1962
|
+
</body>
|
|
1963
|
+
</html>
|