Guest

gnmet9

Nov 18th, 2026
12
0
Never
Not a member of GistPad yet? Sign Up, it unlocks many cool features!
None 264.08 KB | None | 0 0
  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.0, viewport-fit=cover">
  6. <title>gn-math</title>
  7. <link rel="icon" type="image/png" href="favicon.png">
  8. <link rel="icon" type="image/png" sizes="32x32" href="favicon.png">
  9. <link rel="apple-touch-icon" href="favicon.png">
  10. <link rel="manifest" href="manifest.json">
  11. <meta name="theme-color" content="#02040b">
  12. <meta name="title" content="GN-Math">
  13. <meta name="description" content="Play unbl*cked games like Crazy Cattle 3D and DriveMad on GN-Math. Fast, free, no downloads—perfect for school or home.">
  14. <meta property="og:type" content="website">
  15. <meta property="og:url" content="https://gn-math.github.io/">;
  16. <meta property="og:title" content="GN-Math">
  17. <meta property="og:description" content="Play unbl*cked games like Crazy Cattle 3D and DriveMad on GN-Math. Fast, free, no downloads—perfect for school or home.">
  18. <meta name="twitter:card" content="summary_large_image">
  19. <meta name="twitter:url" content="https://gn-math.github.io/">;
  20. <meta name="twitter:title" content="GN-Math">
  21. <meta name="twitter:description" content="Play unbl*cked games like Crazy Cattle 3D and DriveMad on GN-Math. Fast, free, no downloads—perfect for school or home.">
  22. <link rel="preconnect" href="https://fonts.googleapis.com">;
  23. <link rel="preconnect" href="https://fonts.gstatic.com"; crossorigin>
  24. <script>
  25. window.dataLayer = window.dataLayer || [];
  26. function gtag() { dataLayer.push(arguments); }
  27. gtag('js', new Date());
  28. gtag('config', 'G-WX5VS54ZDW');
  29. </script>
  30. <style>
  31. :root {
  32. --neon: #00d4ff;
  33. --neon-rgb: 0, 212, 255;
  34. --neon2: #2f6bff;
  35. --neon2-rgb: 47, 107, 255;
  36. --hot: #ff2bd6;
  37. --ok: #3dffa8;
  38. --warn: #ffd23d;
  39. --danger: #ff3b6b;
  40. --bg0: #02040b;
  41. --bg1: #050a1c;
  42. --panel: rgba(7, 14, 32, 0.78);
  43. --panel-solid: #070e20;
  44. --panel-2: rgba(12, 24, 52, 0.7);
  45. --line: rgba(var(--neon-rgb), 0.16);
  46. --line-strong: rgba(var(--neon-rgb), 0.42);
  47. --text: #e6f4ff;
  48. --muted: #8094b8;
  49. --dim: #4f6185;
  50. --glow: 0 0 10px rgba(var(--neon-rgb), 0.55), 0 0 30px rgba(var(--neon-rgb), 0.22);
  51. --glow-text: 0 0 8px rgba(var(--neon-rgb), 0.8), 0 0 22px rgba(var(--neon-rgb), 0.35);
  52. --cut: 14px;
  53. --card-min: 180px;
  54. --side: 248px;
  55. --top: 72px;
  56. --f-display: 'Orbitron', 'Chakra Petch', system-ui, sans-serif;
  57. --f-ui: 'Chakra Petch', system-ui, -apple-system, 'Segoe UI', sans-serif;
  58. --f-mono: 'Share Tech Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  59. --ease: cubic-bezier(.2, .8, .2, 1);
  60. }
  61. :root[data-accent="ice"] { --neon: #7af7ff; --neon-rgb: 122, 247, 255; --neon2: #00a3ff; --neon2-rgb: 0, 163, 255; }
  62. :root[data-accent="synth"] { --neon: #ff3df2; --neon-rgb: 255, 61, 242; --neon2: #7b2bff; --neon2-rgb: 123, 43, 255; --hot: #00e5ff; }
  63. :root[data-accent="toxic"] { --neon: #3dff8f; --neon-rgb: 61, 255, 143; --neon2: #00b3a1; --neon2-rgb: 0, 179, 161; }
  64. :root[data-accent="solar"] { --neon: #ffb020; --neon-rgb: 255, 176, 32; --neon2: #ff4d2b; --neon2-rgb: 255, 77, 43; --hot: #00d4ff; }
  65. :root[data-size="s"] { --card-min: 140px; }
  66. :root[data-size="l"] { --card-min: 230px; }
  67.  
  68. * { box-sizing: border-box; }
  69. html { color-scheme: dark; scrollbar-color: rgba(var(--neon-rgb), .35) transparent; }
  70. body {
  71. margin: 0;
  72. min-height: 100vh;
  73. font-family: var(--f-ui);
  74. font-size: 15px;
  75. line-height: 1.5;
  76. color: var(--text);
  77. background: var(--bg0);
  78. -webkit-font-smoothing: antialiased;
  79. overflow-x: hidden;
  80. }
  81. ::selection { background: rgba(var(--neon-rgb), .35); color: #fff; }
  82. ::-webkit-scrollbar { width: 10px; height: 10px; }
  83. ::-webkit-scrollbar-thumb { background: rgba(var(--neon-rgb), .25); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
  84. ::-webkit-scrollbar-thumb:hover { background-color: rgba(var(--neon-rgb), .5); }
  85. button, input, select { font: inherit; color: inherit; }
  86. button { cursor: pointer; }
  87. :focus-visible { outline: 2px solid var(--neon); outline-offset: 2px; }
  88. .ic { width: 18px; height: 18px; flex: none; display: inline-block; }
  89. .ic svg { width: 100%; height: 100%; display: block; }
  90. .hidden { display: none !important; }
  91.  
  92. /* ---------- background ---------- */
  93. .bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
  94. background:
  95. radial-gradient(1100px 620px at 85% -15%, rgba(var(--neon-rgb), .20), transparent 60%),
  96. radial-gradient(900px 520px at -10% 20%, rgba(var(--neon2-rgb), .20), transparent 62%),
  97. radial-gradient(700px 400px at 50% 110%, rgba(var(--neon2-rgb), .22), transparent 70%),
  98. linear-gradient(180deg, #02040b 0%, var(--bg1) 55%, #02040b 100%);
  99. }
  100. .floor { position: absolute; left: -50%; width: 200%; bottom: 0; height: 58%;
  101. transform: perspective(380px) rotateX(64deg); transform-origin: 50% 100%; overflow: hidden;
  102. -webkit-mask-image: linear-gradient(to top, #000 0%, rgba(0,0,0,.6) 40%, transparent 92%);
  103. mask-image: linear-gradient(to top, #000 0%, rgba(0,0,0,.6) 40%, transparent 92%);
  104. opacity: .5;
  105. }
  106. .floor::before { content: ''; position: absolute; inset: -64px 0 0 0;
  107. background-image:
  108. linear-gradient(rgba(var(--neon-rgb), .55) 1px, transparent 1px),
  109. linear-gradient(90deg, rgba(var(--neon-rgb), .55) 1px, transparent 1px);
  110. background-size: 64px 64px;
  111. animation: floor 2.6s linear infinite;
  112. }
  113. @keyframes floor { from { transform: translateY(0); } to { transform: translateY(64px); } }
  114. .horizon { position: absolute; left: 0; right: 0; bottom: 58%; height: 1px;
  115. background: linear-gradient(90deg, transparent, rgba(var(--neon-rgb), .7), transparent);
  116. box-shadow: 0 0 30px 6px rgba(var(--neon-rgb), .25); opacity: .55; }
  117. .scan { position: fixed; inset: 0; z-index: 90; pointer-events: none;
  118. background: repeating-linear-gradient(180deg, rgba(255,255,255,.028) 0 1px, transparent 1px 3px);
  119. mix-blend-mode: overlay; }
  120. .vignette { position: fixed; inset: 0; z-index: 1; pointer-events: none;
  121. background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,.55) 100%); }
  122. :root[data-scan="off"] .scan { display: none; }
  123. :root[data-motion="off"] .floor::before, :root[data-motion="off"] .glitch::before, :root[data-motion="off"] .glitch::after { animation: none !important; }
  124. @media (prefers-reduced-motion: reduce) {
  125. .floor::before, .glitch::before, .glitch::after, .sweep, .skeleton::after { animation: none !important; }
  126. }
  127.  
  128. /* ---------- shell ---------- */
  129. .app { position: relative; z-index: 2; display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; }
  130. .side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px;
  131. padding: 22px 16px 18px; border-right: 1px solid var(--line);
  132. background: linear-gradient(180deg, rgba(4, 9, 22, .88), rgba(3, 6, 15, .92));
  133. backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); overflow-y: auto; }
  134. .brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 14px; border-bottom: 1px dashed var(--line); background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
  135. .brand-mark { width: 40px; height: 40px; flex: none; display: grid; place-items: center; color: #001018;
  136. background: linear-gradient(135deg, var(--neon), var(--neon2));
  137. clip-path: polygon(0 0, 75% 0, 100% 25%, 100% 100%, 25% 100%, 0 75%);
  138. box-shadow: var(--glow); }
  139. .brand-mark .ic { width: 22px; height: 22px; }
  140. .brand-text { display: flex; flex-direction: column; line-height: 1.05; }
  141. .logo { font-family: var(--f-display); font-weight: 900; font-size: 20px; letter-spacing: .08em; color: #fff; text-shadow: var(--glow-text); }
  142. .logo b { color: var(--neon); font-weight: 900; }
  143. .brand-sub { font-family: var(--f-mono); font-size: 10.5px; letter-spacing: .32em; color: var(--muted); margin-top: 5px; }
  144.  
  145. .glitch { position: relative; display: inline-block; }
  146. .glitch::before, .glitch::after { content: attr(data-text); position: absolute; inset: 0; pointer-events: none; }
  147. .glitch::before { color: var(--hot); transform: translate(-2px, 0); clip-path: inset(0 0 100% 0); animation: glitch-a 6s infinite steps(1); mix-blend-mode: screen; }
  148. .glitch::after { color: var(--neon); transform: translate(2px, 0); clip-path: inset(100% 0 0 0); animation: glitch-b 6s infinite steps(1); mix-blend-mode: screen; }
  149. @keyframes glitch-a { 0%, 91%, 100% { clip-path: inset(0 0 100% 0); } 92% { clip-path: inset(12% 0 58% 0); } 94% { clip-path: inset(62% 0 8% 0); } 96% { clip-path: inset(30% 0 40% 0); } }
  150. @keyframes glitch-b { 0%, 91%, 100% { clip-path: inset(100% 0 0 0); } 93% { clip-path: inset(48% 0 22% 0); } 95% { clip-path: inset(4% 0 76% 0); } 97% { clip-path: inset(70% 0 2% 0); } }
  151.  
  152. .nav-label { font-family: var(--f-mono); font-size: 10.5px; letter-spacing: .28em; color: var(--dim); padding: 0 10px; margin-bottom: -8px; }
  153. .nav { display: flex; flex-direction: column; gap: 4px; }
  154. .nav-btn { position: relative; display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 12px;
  155. background: transparent; border: 1px solid transparent; color: var(--muted); font-weight: 600; letter-spacing: .04em; font-size: 14.5px;
  156. text-align: left; transition: color .2s, background .2s, border-color .2s;
  157. clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%); }
  158. .nav-btn:hover { color: var(--text); background: rgba(var(--neon-rgb), .06); }
  159. .nav-btn.active { color: #fff; background: linear-gradient(90deg, rgba(var(--neon-rgb), .18), rgba(var(--neon-rgb), .02)); border-color: rgba(var(--neon-rgb), .25); }
  160. .nav-btn.active::before { content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; background: var(--neon); box-shadow: var(--glow); }
  161. .nav-btn.active .ic { color: var(--neon); filter: drop-shadow(0 0 6px rgba(var(--neon-rgb), .8)); }
  162. .nav-count { margin-left: auto; font-family: var(--f-mono); font-size: 12px; color: var(--dim); }
  163. .nav-btn.active .nav-count { color: var(--neon); }
  164.  
  165. .side-card { margin-top: auto; padding: 14px; border: 1px solid var(--line); background: rgba(var(--neon-rgb), .03);
  166. clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px)); }
  167. .side-card h4 { margin: 0 0 8px; font-family: var(--f-mono); font-weight: 400; font-size: 11px; letter-spacing: .24em; color: var(--muted); }
  168. .meter { height: 6px; background: rgba(var(--neon-rgb), .1); position: relative; overflow: hidden; }
  169. .meter > i { position: absolute; inset: 0 auto 0 0; width: 0%; background: linear-gradient(90deg, var(--neon2), var(--neon)); box-shadow: var(--glow); transition: width .6s var(--ease); }
  170. .meter-text { display: flex; justify-content: space-between; margin-top: 8px; font-family: var(--f-mono); font-size: 12px; color: var(--muted); }
  171. .side-links { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 0 6px; }
  172. .side-links button { background: none; border: 0; padding: 2px 0; color: var(--dim); font-size: 12.5px; letter-spacing: .04em; }
  173. .side-links button:hover { color: var(--neon); }
  174.  
  175. .main { min-width: 0; display: flex; flex-direction: column; }
  176. .top { position: sticky; top: 0; z-index: 50; height: var(--top); display: flex; align-items: center; gap: 12px; padding: 0 28px;
  177. background: linear-gradient(180deg, rgba(2, 4, 11, .92), rgba(2, 4, 11, .62));
  178. backdrop-filter: blur(16px) saturate(140%); -webkit-backdrop-filter: blur(16px) saturate(140%);
  179. border-bottom: 1px solid var(--line); }
  180. .top .brand { display: none; border: 0; padding: 0; }
  181. .search { position: relative; flex: 1; max-width: 560px; }
  182. .search .ic { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--neon); pointer-events: none; }
  183. .search input { width: 100%; height: 44px; padding: 0 76px 0 44px; border: 1px solid var(--line-strong); background: rgba(3, 8, 20, .75); color: var(--text);
  184. outline: none; font-size: 15px; letter-spacing: .02em; transition: border-color .2s, box-shadow .2s;
  185. clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px)); }
  186. .search input::placeholder { color: var(--dim); }
  187. .search input:focus { border-color: var(--neon); box-shadow: inset 0 0 0 1px rgba(var(--neon-rgb), .4), inset 0 0 24px rgba(var(--neon-rgb), .12); }
  188. .kbd { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-family: var(--f-mono); font-size: 11px; color: var(--muted);
  189. border: 1px solid var(--line-strong); padding: 1px 7px; pointer-events: none; }
  190. .search-clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; display: grid; place-items: center; background: none; border: 0; color: var(--muted); }
  191. .search-clear:hover { color: var(--neon); }
  192. .top-actions { display: flex; gap: 8px; margin-left: auto; }
  193.  
  194. .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
  195. border: 1px solid var(--line-strong); background: rgba(var(--neon-rgb), .06); color: var(--text);
  196. font-weight: 600; font-size: 13.5px; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap;
  197. transition: background .2s, border-color .2s, color .2s, box-shadow .2s, transform .15s;
  198. clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 10px 100%, 0 calc(100% - 10px)); }
  199. .btn:hover { background: rgba(var(--neon-rgb), .16); border-color: var(--neon); color: #fff; }
  200. .btn:active { transform: translateY(1px); }
  201. .btn.primary { background: linear-gradient(135deg, var(--neon), var(--neon2)); color: #00111a; border-color: transparent; text-shadow: none; }
  202. .btn.primary:hover { filter: brightness(1.12); color: #000; }
  203. .btn.danger { border-color: rgba(255, 59, 107, .5); background: rgba(255, 59, 107, .08); }
  204. .btn.danger:hover { border-color: var(--danger); background: rgba(255, 59, 107, .2); }
  205. .btn.icon { width: 40px; padding: 0; }
  206. .btn > svg, .rail-btn > svg { width: 17px; height: 17px; flex: none; }
  207. .btn.sm { height: 32px; padding: 0 12px; font-size: 12px; }
  208. .btn.sm.icon { width: 32px; }
  209. .btn.spin .ic { animation: spin .8s linear infinite; }
  210. @keyframes spin { to { transform: rotate(360deg); } }
  211.  
  212. .view { padding: 28px 28px 80px; min-width: 0; }
  213.  
  214. /* ---------- hero ---------- */
  215. .hero { position: relative; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr); gap: 28px; padding: 34px;
  216. border: 1px solid var(--line-strong); background: linear-gradient(120deg, rgba(var(--neon2-rgb), .16), rgba(3, 8, 20, .82) 55%);
  217. clip-path: polygon(0 0, calc(100% - 28px) 0, 100% 28px, 100% 100%, 28px 100%, 0 calc(100% - 28px)); overflow: hidden; isolation: isolate; }
  218. .hero-art { position: absolute; inset: 0; z-index: -1; background-size: cover; background-position: center; opacity: .28; filter: blur(18px) saturate(1.4); transform: scale(1.2); }
  219. .hero::after { content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  220. background: linear-gradient(90deg, rgba(2, 4, 11, .92) 0%, rgba(2, 4, 11, .55) 60%, rgba(2, 4, 11, .25) 100%); }
  221. .hero-corner { position: absolute; width: 22px; height: 22px; border-color: var(--neon); border-style: solid; filter: drop-shadow(0 0 6px rgba(var(--neon-rgb), .8)); }
  222. .hero-corner.tl { top: 10px; left: 10px; border-width: 2px 0 0 2px; }
  223. .hero-corner.br { bottom: 10px; right: 10px; border-width: 0 2px 2px 0; }
  224. .eyebrow { font-family: var(--f-mono); font-size: 12px; letter-spacing: .3em; color: var(--neon); text-transform: uppercase; display: flex; align-items: center; gap: 10px; }
  225. .eyebrow .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 10px var(--ok); animation: pulse 1.8s ease-in-out infinite; }
  226. @keyframes pulse { 50% { opacity: .35; } }
  227. .hero h1 { margin: 14px 0 10px; font-family: var(--f-display); font-weight: 900; font-size: clamp(30px, 4.4vw, 58px); line-height: 1.02; letter-spacing: .03em; text-transform: uppercase; }
  228. .hero h1 .accent { color: var(--neon); text-shadow: var(--glow-text); }
  229. .hero p { margin: 0 0 24px; max-width: 54ch; color: var(--muted); font-size: 16px; }
  230. .hero-cta { display: flex; flex-wrap: wrap; gap: 10px; }
  231. .hero-cta .btn { height: 46px; padding: 0 22px; font-size: 14px; }
  232. .continue { display: flex; align-items: center; gap: 14px; margin-top: 22px; padding: 10px; max-width: 460px; border: 1px solid var(--line); background: rgba(2, 4, 11, .6); width: 100%; text-align: left; color: inherit;
  233. clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 0 100%); transition: border-color .2s, background .2s; }
  234. .continue:hover { border-color: var(--neon); background: rgba(var(--neon-rgb), .08); }
  235. .continue img { width: 56px; height: 56px; object-fit: cover; flex: none; background: var(--panel-2); }
  236. .continue .c-label { font-family: var(--f-mono); font-size: 11px; letter-spacing: .24em; color: var(--neon); }
  237. .continue .c-name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  238. .continue .c-meta { font-size: 12.5px; color: var(--muted); }
  239. .continue > div { min-width: 0; flex: 1; }
  240. .continue .play-dot { width: 40px; height: 40px; display: grid; place-items: center; flex: none; color: #00111a; background: var(--neon); box-shadow: var(--glow); clip-path: polygon(0 0, 100% 50%, 0 100%); }
  241.  
  242. .stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-content: center; }
  243. .stat { position: relative; padding: 16px 16px 14px; border: 1px solid var(--line); background: rgba(2, 6, 16, .72);
  244. clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 0 100%); }
  245. .stat::before { content: ''; position: absolute; left: 0; top: 0; width: 26px; height: 2px; background: var(--neon); box-shadow: var(--glow); }
  246. .stat-k { font-family: var(--f-mono); font-size: 11px; letter-spacing: .24em; color: var(--muted); text-transform: uppercase; }
  247. .stat-v { font-family: var(--f-display); font-weight: 800; font-size: 28px; margin-top: 4px; letter-spacing: .02em; }
  248. .stat-v small { font-family: var(--f-mono); font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 2px; }
  249.  
  250. /* ---------- sections + rails ---------- */
  251. .section { margin-top: 40px; }
  252. .section-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
  253. .section-idx { font-family: var(--f-mono); font-size: 13px; color: var(--neon); border: 1px solid var(--line-strong); padding: 1px 7px; }
  254. .section-head h2 { margin: 0; font-family: var(--f-display); font-weight: 800; font-size: 18px; letter-spacing: .1em; text-transform: uppercase; }
  255. .section-head .rule { flex: 1; height: 1px; background: linear-gradient(90deg, var(--line-strong), transparent); }
  256. .link { background: none; border: 0; color: var(--neon); font-family: var(--f-mono); font-size: 12.5px; letter-spacing: .14em; text-transform: uppercase; padding: 4px 2px; }
  257. .link:hover { text-shadow: var(--glow-text); }
  258. .rail-wrap { position: relative; }
  259. .rail { display: grid; grid-auto-flow: column; grid-auto-columns: 176px; gap: 16px; overflow-x: auto; padding: 6px 2px 14px; scroll-snap-type: x mandatory; scrollbar-width: thin; }
  260. .rail > * { scroll-snap-align: start; }
  261. .rail-btn { position: absolute; top: calc(50% - 30px); z-index: 4; width: 38px; height: 60px; display: grid; place-items: center;
  262. border: 1px solid var(--line-strong); background: rgba(2, 4, 11, .85); color: var(--neon); opacity: 0; transition: opacity .2s; }
  263. .rail-btn.l { left: -6px; } .rail-btn.r { right: -6px; }
  264. .rail-wrap:hover .rail-btn { opacity: 1; }
  265. .rail-btn:hover { background: rgba(var(--neon-rgb), .18); }
  266.  
  267. /* ---------- cards ---------- */
  268. .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--card-min), 1fr)); gap: 18px; }
  269. .card { position: relative; cursor: pointer; transition: transform .25s var(--ease), filter .25s; outline: none; }
  270. .card:hover, .card:focus-visible { transform: translateY(-5px); filter: drop-shadow(0 0 14px rgba(var(--neon-rgb), .45)); }
  271. .card-frame { padding: 1px; background: linear-gradient(160deg, rgba(var(--neon-rgb), .32), rgba(var(--neon-rgb), .06) 40%, rgba(var(--neon2-rgb), .22));
  272. clip-path: polygon(0 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% 100%, var(--cut) 100%, 0 calc(100% - var(--cut))); transition: background .25s; }
  273. .card:hover .card-frame, .card:focus-visible .card-frame { background: linear-gradient(160deg, var(--neon), var(--neon2) 55%, var(--hot)); }
  274. .card-body { background: linear-gradient(180deg, #0a1430, #050a18); clip-path: polygon(0 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% 100%, var(--cut) 100%, 0 calc(100% - var(--cut))); }
  275. .cover { position: relative; aspect-ratio: 1; overflow: hidden; background:
  276. linear-gradient(135deg, rgba(var(--neon-rgb), .08) 25%, transparent 25% 50%, rgba(var(--neon-rgb), .08) 50% 75%, transparent 75%) 0 0 / 18px 18px, #060d22; }
  277. .cover img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transform: scale(1.02); transition: opacity .4s, transform .5s var(--ease), filter .3s; }
  278. .cover img.loaded { opacity: 1; }
  279. .cover img.err { display: none; }
  280. .card:hover .cover img { transform: scale(1.09); filter: saturate(1.25) contrast(1.05); }
  281. .cover::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, transparent 55%, rgba(2, 4, 11, .85)); }
  282. .sweep { position: absolute; left: 0; right: 0; top: -30%; height: 30%; z-index: 2; pointer-events: none; opacity: 0;
  283. background: linear-gradient(180deg, transparent, rgba(var(--neon-rgb), .35), transparent); }
  284. .card:hover .sweep { opacity: 1; animation: sweep 1.1s var(--ease) 1; }
  285. @keyframes sweep { from { top: -30%; } to { top: 110%; } }
  286. .play-hint { position: absolute; z-index: 3; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; display: grid; place-items: center;
  287. background: rgba(2, 4, 11, .55); border: 1px solid var(--neon); color: var(--neon); box-shadow: var(--glow);
  288. clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 10px 100%, 0 calc(100% - 10px));
  289. opacity: 0; transform: scale(.7); transition: opacity .2s, transform .25s var(--ease); }
  290. .play-hint .ic { width: 22px; height: 22px; margin-left: 3px; }
  291. .card:hover .play-hint { opacity: 1; transform: scale(1); }
  292. .badges { position: absolute; z-index: 3; left: 8px; top: 8px; display: flex; gap: 5px; flex-wrap: wrap; }
  293. .badge { font-family: var(--f-mono); font-size: 10.5px; letter-spacing: .12em; padding: 2px 6px; line-height: 1.3; color: #001018; background: var(--neon); }
  294. .badge.save { background: var(--ok); }
  295. .badge.new { background: var(--hot); color: #fff; }
  296. .badge.ext { background: var(--warn); }
  297. .fav { position: absolute; z-index: 4; right: 8px; top: 8px; width: 32px; height: 32px; display: grid; place-items: center;
  298. background: rgba(2, 4, 11, .65); border: 1px solid rgba(255, 255, 255, .12); color: rgba(255, 255, 255, .7);
  299. opacity: 0; transition: opacity .2s, color .2s, border-color .2s, transform .15s; }
  300. .fav .ic { width: 16px; height: 16px; }
  301. .card:hover .fav, .fav.on, .card:focus-within .fav { opacity: 1; }
  302. .fav:hover { color: var(--warn); border-color: var(--warn); transform: scale(1.08); }
  303. .fav.on { color: var(--warn); border-color: rgba(255, 210, 61, .6); }
  304. .fav.on svg { fill: currentColor; filter: drop-shadow(0 0 5px rgba(255, 210, 61, .7)); }
  305. .meta { padding: 10px 12px 12px; }
  306. .meta h3 { margin: 0; font-size: 14.5px; font-weight: 700; line-height: 1.25; letter-spacing: .01em; min-height: 2.5em;
  307. display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; transition: color .2s, text-shadow .2s; }
  308. .card:hover .meta h3 { color: #fff; text-shadow: var(--glow-text); }
  309. .sub { display: flex; align-items: center; gap: 8px; margin-top: 7px; font-family: var(--f-mono); font-size: 11.5px; color: var(--muted); min-width: 0; }
  310. .sub .tag { color: var(--neon); text-transform: uppercase; letter-spacing: .08em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  311. .sub .plays { margin-left: auto; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
  312. .sub .plays .ic { width: 11px; height: 11px; }
  313.  
  314. .skeleton { position: relative; overflow: hidden; background: rgba(var(--neon-rgb), .05); border: 1px solid var(--line);
  315. clip-path: polygon(0 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% 100%, var(--cut) 100%, 0 calc(100% - var(--cut))); aspect-ratio: .78; }
  316. .skeleton::after { content: ''; position: absolute; inset: 0; transform: translateX(-100%);
  317. background: linear-gradient(90deg, transparent, rgba(var(--neon-rgb), .12), transparent); animation: shimmer 1.4s infinite; }
  318. @keyframes shimmer { to { transform: translateX(100%); } }
  319.  
  320. /* ---------- games toolbar ---------- */
  321. .page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 18px; }
  322. .page-head h1 { margin: 6px 0 0; font-family: var(--f-display); font-weight: 900; font-size: clamp(26px, 3.4vw, 40px); letter-spacing: .06em; text-transform: uppercase; }
  323. .page-head h1 .accent { color: var(--neon); text-shadow: var(--glow-text); }
  324. .toolbar { position: sticky; top: var(--top); z-index: 30; display: flex; align-items: center; gap: 12px; padding: 12px 0; margin: 0 0 18px;
  325. background: linear-gradient(180deg, rgba(2, 4, 11, .94) 70%, rgba(2, 4, 11, 0)); }
  326. .chips { display: flex; gap: 8px; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; padding: 2px 24px 2px 2px;
  327. -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 40px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 40px), transparent); }
  328. .chips::-webkit-scrollbar { display: none; }
  329. .chip { flex: none; height: 34px; padding: 0 14px; border: 1px solid var(--line); background: rgba(3, 8, 20, .7); color: var(--muted);
  330. font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; transition: all .2s;
  331. clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px)); }
  332. .chip:hover { color: var(--text); border-color: var(--line-strong); }
  333. .chip.on { color: #00111a; background: var(--neon); border-color: var(--neon); box-shadow: var(--glow); }
  334. .chip .n { font-family: var(--f-mono); font-size: 11px; opacity: .7; margin-left: 4px; }
  335. .select { position: relative; flex: none; }
  336. .select select { appearance: none; -webkit-appearance: none; height: 38px; padding: 0 36px 0 14px; border: 1px solid var(--line-strong); background: rgba(3, 8, 20, .85);
  337. color: var(--text); font-size: 13.5px; font-weight: 600; letter-spacing: .04em; outline: none;
  338. clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 10px 100%, 0 calc(100% - 10px)); }
  339. .select select:focus { border-color: var(--neon); }
  340. .select select option { background: var(--panel-solid); }
  341. .select .ic { position: absolute; right: 12px; top: 50%; width: 14px; height: 14px; transform: translateY(-50%) rotate(90deg); pointer-events: none; color: var(--neon); }
  342. .count { font-family: var(--f-mono); font-size: 12.5px; color: var(--muted); letter-spacing: .12em; white-space: nowrap; }
  343. .count b { color: var(--neon); font-weight: 400; }
  344.  
  345. /* ---------- library ---------- */
  346. .seg { display: inline-flex; padding: 4px; gap: 4px; border: 1px solid var(--line-strong); background: rgba(3, 8, 20, .8);
  347. clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px)); }
  348. .seg button { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 18px; border: 0; background: transparent; color: var(--muted);
  349. font-weight: 700; font-size: 13.5px; letter-spacing: .1em; text-transform: uppercase; transition: all .2s;
  350. clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px)); }
  351. .seg button:hover { color: var(--text); }
  352. .seg button.on { color: #00111a; background: linear-gradient(135deg, var(--neon), var(--neon2)); }
  353. .seg .n { font-family: var(--f-mono); font-size: 12px; opacity: .75; }
  354. .lib-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
  355. .lib-bar .spacer { flex: 1; }
  356.  
  357. .list { display: flex; flex-direction: column; gap: 10px; }
  358. .row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 16px; padding: 10px 14px 10px 10px;
  359. border: 1px solid var(--line); background: linear-gradient(90deg, rgba(10, 20, 46, .8), rgba(4, 9, 22, .7));
  360. clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 0 100%); transition: border-color .2s, background .2s; }
  361. .row:hover { border-color: var(--line-strong); background: linear-gradient(90deg, rgba(var(--neon-rgb), .1), rgba(4, 9, 22, .7)); }
  362. .row-thumb { width: 64px; height: 64px; object-fit: cover; background: #060d22; display: block; cursor: pointer; }
  363. .row-main { min-width: 0; }
  364. .row-title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
  365. .row-title:hover { color: var(--neon); }
  366. .row-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 3px; font-family: var(--f-mono); font-size: 12.5px; color: var(--muted); }
  367. .row-meta span { display: inline-flex; align-items: center; gap: 6px; }
  368. .row-meta .ic { width: 13px; height: 13px; color: var(--neon); }
  369. .row-meta .warn { color: var(--warn); }
  370. .row-actions { display: flex; gap: 8px; }
  371. .when { color: var(--neon); }
  372.  
  373. .panel { position: relative; padding: 20px; border: 1px solid var(--line); background: rgba(5, 11, 26, .78);
  374. clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 18px 100%, 0 calc(100% - 18px)); }
  375. .panel h3 { margin: 0 0 4px; font-family: var(--f-display); font-size: 15px; letter-spacing: .1em; text-transform: uppercase; }
  376. .panel p { margin: 0; color: var(--muted); font-size: 14px; }
  377. .save-top { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; margin-bottom: 22px; }
  378. .save-top .meter { height: 10px; margin-top: 14px; }
  379. .save-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
  380. .note { margin-top: 18px; display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; color: var(--muted); }
  381. .note .ic { color: var(--neon); margin-top: 2px; }
  382.  
  383. .empty { display: grid; place-items: center; text-align: center; padding: 56px 20px; border: 1px dashed var(--line-strong);
  384. background: repeating-linear-gradient(135deg, rgba(var(--neon-rgb), .03) 0 12px, transparent 12px 24px); }
  385. .empty .big { width: 64px; height: 64px; display: grid; place-items: center; color: var(--neon); border: 1px solid var(--line-strong); margin-bottom: 16px;
  386. clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 14px 100%, 0 calc(100% - 14px)); box-shadow: inset 0 0 22px rgba(var(--neon-rgb), .2); }
  387. .empty .big .ic { width: 28px; height: 28px; }
  388. .empty h3 { margin: 0 0 6px; font-family: var(--f-display); letter-spacing: .1em; text-transform: uppercase; font-size: 17px; }
  389. .empty p { margin: 0 0 18px; color: var(--muted); max-width: 46ch; }
  390.  
  391. /* ---------- viewer ---------- */
  392. #zoneViewer { position: fixed; inset: 0; z-index: 1000; display: none; flex-direction: column; background: #000; }
  393. #zoneViewer.open { display: flex; animation: viewer-in .35s var(--ease); }
  394. @keyframes viewer-in { from { opacity: 0; transform: scale(.985); } to { opacity: 1; transform: none; } }
  395. .hud { position: relative; display: flex; align-items: center; gap: 14px; height: 58px; padding: 0 14px; flex: none;
  396. background: linear-gradient(180deg, #050b1d, #02050e); border-bottom: 1px solid var(--line-strong); }
  397. .hud::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: linear-gradient(90deg, transparent, var(--neon), transparent); box-shadow: var(--glow); }
  398. .hud-title { min-width: 0; flex: 1; display: flex; align-items: center; gap: 12px; }
  399. .hud-title > div { min-width: 0; }
  400. #zoneName { margin: 0; font-family: var(--f-display); font-weight: 800; font-size: 16px; letter-spacing: .06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-transform: uppercase; }
  401. #zoneAuthor { display: block; font-size: 12.5px; color: var(--muted); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  402. #zoneAuthor:hover { color: var(--neon); }
  403. .hud-timer { display: flex; align-items: center; gap: 8px; padding: 0 12px; height: 32px; border: 1px solid var(--line); font-family: var(--f-mono); font-size: 14px; color: var(--neon); letter-spacing: .1em; }
  404. .hud-timer .rec { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 8px var(--danger); animation: pulse 1.4s infinite; }
  405. .hud-actions { display: flex; gap: 6px; }
  406. .hud .btn { height: 36px; font-size: 12px; padding: 0 12px; }
  407. .hud .btn.icon { width: 36px; padding: 0; }
  408. .hud .btn.fav-on { color: var(--warn); border-color: rgba(255, 210, 61, .6); }
  409. .hud .btn.fav-on svg { fill: currentColor; }
  410. .stage { position: relative; flex: 1; min-height: 0; background: #000; }
  411. #zoneFrame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; background: #000; }
  412. .loader { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; background: radial-gradient(circle at center, #071433, #000 70%); }
  413. .loader-box { text-align: center; font-family: var(--f-mono); letter-spacing: .3em; color: var(--neon); font-size: 13px; }
  414. .loader-ring { width: 72px; height: 72px; margin: 0 auto 18px; border: 2px solid rgba(var(--neon-rgb), .15); border-top-color: var(--neon); border-right-color: var(--neon); border-radius: 50%;
  415. animation: spin .9s linear infinite; box-shadow: var(--glow); }
  416. .loader-name { margin-top: 8px; color: var(--muted); letter-spacing: .1em; font-size: 12px; }
  417.  
  418. /* ---------- popup ---------- */
  419. #popupOverlay { position: fixed; inset: 0; z-index: 2000; display: none; align-items: center; justify-content: center; padding: 16px;
  420. background: rgba(1, 3, 9, .72); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
  421. #popupOverlay.open { display: flex; animation: fade .2s ease; }
  422. @keyframes fade { from { opacity: 0; } }
  423. .popup { width: 100%; max-width: 540px; max-height: min(86vh, 760px); display: flex; flex-direction: column; padding: 1px;
  424. background: linear-gradient(160deg, var(--neon), rgba(var(--neon-rgb), .1) 40%, var(--neon2));
  425. clip-path: polygon(0 0, calc(100% - 22px) 0, 100% 22px, 100% 100%, 22px 100%, 0 calc(100% - 22px));
  426. animation: pop .28s var(--ease); filter: drop-shadow(0 0 30px rgba(var(--neon-rgb), .25)); }
  427. .popup.wide { max-width: 720px; }
  428. @keyframes pop { from { transform: translateY(14px) scale(.97); } }
  429. .popup-in { display: flex; flex-direction: column; min-height: 0; background: linear-gradient(180deg, #081230, #040918);
  430. clip-path: polygon(0 0, calc(100% - 22px) 0, 100% 22px, 100% 100%, 22px 100%, 0 calc(100% - 22px)); }
  431. .popup-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 14px 22px; border-bottom: 1px solid var(--line); }
  432. #popupTitle { margin: 0; font-family: var(--f-display); font-size: 16px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
  433. #popupTitle::before { content: '// '; color: var(--neon); }
  434. #popupBody { padding: 20px 22px 24px; overflow-y: auto; color: var(--text); }
  435. #popupBody a { color: var(--neon); }
  436. #popupBody h2, #popupBody h3 { font-family: var(--f-display); letter-spacing: .06em; }
  437. #popupBody h2 { font-size: 18px; } #popupBody h3 { font-size: 14px; color: var(--neon); margin-top: 22px; }
  438. #popupBody p, #popupBody li { color: #c4d4ee; }
  439. .field { margin-bottom: 18px; }
  440. .field label, .field .lbl { display: block; font-family: var(--f-mono); font-size: 11.5px; letter-spacing: .24em; color: var(--muted); text-transform: uppercase; margin-bottom: 8px; }
  441. .input { width: 100%; height: 44px; padding: 0 14px; border: 1px solid var(--line-strong); background: rgba(2, 6, 16, .8); color: var(--text); outline: none;
  442. clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 10px 100%, 0 calc(100% - 10px)); }
  443. .input:focus { border-color: var(--neon); box-shadow: inset 0 0 18px rgba(var(--neon-rgb), .12); }
  444. .swatches { display: flex; gap: 10px; flex-wrap: wrap; }
  445. .swatch { width: 46px; height: 46px; border: 2px solid transparent; padding: 3px; background: none; clip-path: polygon(0 0, 75% 0, 100% 25%, 100% 100%, 25% 100%, 0 75%); }
  446. .swatch i { display: block; width: 100%; height: 100%; clip-path: polygon(0 0, 75% 0, 100% 25%, 100% 100%, 25% 100%, 0 75%); }
  447. .swatch.on { border-color: #fff; }
  448. .toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-top: 1px solid var(--line); }
  449. .toggle-row:first-child { border-top: 0; }
  450. .toggle-row b { display: block; font-size: 14.5px; }
  451. .toggle-row span { font-size: 13px; color: var(--muted); }
  452. .switch { position: relative; width: 52px; height: 26px; flex: none; border: 1px solid var(--line-strong); background: rgba(2, 6, 16, .8); padding: 0; }
  453. .switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: var(--dim); transition: transform .25s var(--ease), background .2s; }
  454. .switch.on { border-color: var(--neon); background: rgba(var(--neon-rgb), .16); }
  455. .switch.on::after { transform: translateX(26px); background: var(--neon); box-shadow: var(--glow); }
  456. .kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 10px 18px; margin: 0; }
  457. .kv dt { font-family: var(--f-mono); font-size: 12px; letter-spacing: .18em; color: var(--muted); text-transform: uppercase; padding-top: 2px; }
  458. .kv dd { margin: 0; overflow-wrap: anywhere; }
  459. .btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
  460. .btn-row.end { justify-content: flex-end; }
  461. code { font-family: var(--f-mono); color: var(--neon); }
  462.  
  463. /* ---------- save cards ---------- */
  464. .save-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(440px, 1fr)); gap: 16px; }
  465. .save-card { display: grid; grid-template-columns: 124px minmax(0, 1fr); gap: 18px; padding: 14px; border: 1px solid var(--line);
  466. background: linear-gradient(135deg, rgba(12, 24, 54, .88), rgba(4, 9, 22, .78)); transition: border-color .2s, box-shadow .2s;
  467. clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 16px 100%, 0 calc(100% - 16px)); }
  468. .save-card:hover { border-color: var(--line-strong); box-shadow: inset 0 0 40px rgba(var(--neon-rgb), .06); }
  469. .sc-cover { position: relative; aspect-ratio: 1; align-self: start; overflow: hidden; display: grid; place-items: center; color: var(--neon); background: #060d22; cursor: pointer;
  470. clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px)); }
  471. .sc-cover > .ic { width: 34px; height: 34px; }
  472. .sc-cover img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .4s var(--ease); }
  473. .sc-cover:hover img { transform: scale(1.08); }
  474. .sc-play { position: absolute; inset: 0; display: grid; place-items: center; color: var(--neon); background: rgba(2, 4, 11, .5); opacity: 0; transition: opacity .2s; }
  475. .sc-play .ic { width: 32px; height: 32px; filter: drop-shadow(0 0 8px rgba(var(--neon-rgb), .9)); }
  476. .sc-cover:hover .sc-play { opacity: 1; }
  477. .sc-main { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
  478. .sc-top { display: flex; align-items: center; gap: 8px; }
  479. .src { display: inline-block; font-family: var(--f-mono); font-size: 10.5px; letter-spacing: .14em; padding: 2px 7px; border: 1px solid; white-space: nowrap; }
  480. .src.ok { color: var(--ok); border-color: rgba(61, 255, 168, .4); background: rgba(61, 255, 168, .08); }
  481. .src.manual { color: var(--neon); border-color: var(--line-strong); background: rgba(var(--neon-rgb), .08); }
  482. .src.auto { color: var(--warn); border-color: rgba(255, 210, 61, .4); background: rgba(255, 210, 61, .08); }
  483. .sc-id { margin-left: auto; font-family: var(--f-mono); font-size: 12px; color: var(--dim); }
  484. .sc-name { margin: 0; font-family: var(--f-display); font-weight: 800; font-size: 17px; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
  485. .sc-name:hover { color: var(--neon); text-shadow: var(--glow-text); }
  486. .sc-by { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 13px; color: var(--muted); }
  487. .sc-by:empty { display: none; }
  488. .sc-by .tag { font-family: var(--f-mono); font-size: 11px; color: var(--neon); text-transform: uppercase; letter-spacing: .08em; }
  489. .sc-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 4px 0 2px; }
  490. .sc-stats > div { min-width: 0; padding: 6px 8px; border-left: 2px solid var(--line-strong); background: rgba(var(--neon-rgb), .04); }
  491. .sc-stats dt { font-family: var(--f-mono); font-size: 10px; letter-spacing: .14em; color: var(--dim); text-transform: uppercase; white-space: nowrap; }
  492. .sc-stats dd { margin: 2px 0 0; font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  493. .sc-keys { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
  494. .kchip { max-width: 100%; font-size: 11.5px; padding: 2px 7px; border: 1px solid var(--line); background: rgba(2, 6, 16, .7); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  495. .kchip.db { color: var(--hot); }
  496. .kmore { font-family: var(--f-mono); font-size: 11.5px; color: var(--muted); }
  497. .sc-warn { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--warn); }
  498. .sc-warn .ic { width: 14px; height: 14px; }
  499. .sc-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; padding-top: 6px; }
  500. .src-legend { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; font-size: 13.5px; color: var(--muted); }
  501. .src-legend > div { display: flex; align-items: center; gap: 10px; }
  502. .src-legend .src { min-width: 152px; text-align: center; }
  503. .unl-note { margin: -6px 0 14px; color: var(--muted); font-size: 14px; }
  504. .unl-thumb { display: grid; place-items: center; color: var(--muted); border: 1px dashed var(--line-strong); background: transparent; }
  505. .sd-head { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; }
  506. .sd-head img, .sd-ph { width: 88px; height: 88px; flex: none; object-fit: cover; display: grid; place-items: center; color: var(--neon); background: #060d22;
  507. clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px)); }
  508. #popupBody .sd-head h2 { margin: 8px 0 2px; font-size: 20px; overflow-wrap: anywhere; }
  509. #popupBody .sd-head p { margin: 0; font-size: 13px; color: var(--muted); }
  510. #popupBody .sd-src { margin: 0 0 16px; font-size: 13.5px; color: var(--muted); }
  511. .ktable { display: flex; flex-direction: column; border: 1px solid var(--line); }
  512. .krow { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border-top: 1px solid var(--line); }
  513. .krow:first-child { border-top: 0; }
  514. .krow > div { min-width: 0; display: flex; flex-direction: column; }
  515. .krow code { font-size: 12.5px; overflow-wrap: anywhere; }
  516. .krow small { font-family: var(--f-mono); font-size: 11.5px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  517. .krow > span { font-family: var(--f-mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
  518. .pick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; max-height: 52vh; overflow-y: auto; padding-right: 4px; }
  519. .pick { display: flex; align-items: center; gap: 10px; padding: 6px; border: 1px solid var(--line); background: rgba(2, 6, 16, .6); color: var(--text); text-align: left; transition: border-color .2s, background .2s; }
  520. .pick:hover { border-color: var(--neon); background: rgba(var(--neon-rgb), .1); }
  521. .pick img { width: 44px; height: 44px; flex: none; object-fit: cover; background: #060d22; }
  522. .pick span { min-width: 0; display: flex; flex-direction: column; }
  523. .pick b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  524. .pick small { font-family: var(--f-mono); font-size: 11px; color: var(--muted); }
  525. .hud-save { display: flex; align-items: center; gap: 7px; height: 32px; padding: 0 10px; border: 1px solid rgba(61, 255, 168, .45); background: rgba(61, 255, 168, .08);
  526. color: var(--ok); font-family: var(--f-mono); font-size: 12px; letter-spacing: .1em; white-space: nowrap; }
  527. .hud-save .ic { width: 15px; height: 15px; }
  528. .hud-save:hover { background: rgba(61, 255, 168, .18); }
  529. .hud-save.flash { animation: saveflash 1.1s ease; }
  530. @keyframes saveflash { 30% { background: rgba(61, 255, 168, .32); box-shadow: 0 0 18px rgba(61, 255, 168, .8); } }
  531. .link-save { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none; color: var(--ok); font: inherit; }
  532. .link-save .ic { color: var(--ok) !important; }
  533. .link-save:hover { text-decoration: underline; }
  534.  
  535. /* ---------- toasts ---------- */
  536. .toasts { position: fixed; right: 18px; bottom: 18px; z-index: 3000; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; pointer-events: none; }
  537. .toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; min-width: 240px; max-width: 380px; padding: 12px 16px; border: 1px solid var(--line-strong); border-left: 3px solid var(--neon);
  538. background: rgba(4, 9, 22, .96); box-shadow: 0 10px 40px rgba(0, 0, 0, .5), var(--glow); font-size: 14px; animation: toast-in .3s var(--ease); }
  539. .toast.ok { border-left-color: var(--ok); } .toast.err { border-left-color: var(--danger); }
  540. .toast .ic { color: var(--neon); } .toast.ok .ic { color: var(--ok); } .toast.err .ic { color: var(--danger); }
  541. .toast button { margin-left: auto; }
  542. .toast.out { opacity: 0; transform: translateX(20px); transition: all .3s; }
  543. @keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }
  544.  
  545. /* ---------- mobile ---------- */
  546. .bottom-nav { display: none; }
  547. @media (max-width: 1080px) {
  548. .hero { grid-template-columns: 1fr; }
  549. .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  550. .save-top { grid-template-columns: 1fr; }
  551. }
  552. @media (max-width: 860px) {
  553. :root { --top: 112px; }
  554. .app { grid-template-columns: 1fr; }
  555. .side { display: none; }
  556. .top { flex-wrap: wrap; height: auto; padding: 12px 16px; gap: 10px; }
  557. .top .brand { display: flex; }
  558. .top .brand-mark { width: 34px; height: 34px; }
  559. .top .logo { font-size: 17px; }
  560. .top .brand-sub { display: none; }
  561. .search { order: 3; flex-basis: 100%; max-width: none; }
  562. .kbd { display: none; }
  563. .view { padding: 18px 16px calc(96px + env(safe-area-inset-bottom)); }
  564. .hero { padding: 24px 20px; gap: 20px; }
  565. .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  566. .stat-v { font-size: 22px; }
  567. .rail { grid-auto-columns: 148px; gap: 12px; }
  568. .rail-btn { display: none; }
  569. .grid { grid-template-columns: repeat(auto-fill, minmax(min(var(--card-min), 150px), 1fr)); gap: 12px; }
  570. .toolbar { flex-wrap: wrap; gap: 10px; }
  571. .chips { order: 3; flex-basis: 100%; }
  572. .fav { opacity: 1; }
  573. .row { grid-template-columns: 56px minmax(0, 1fr); }
  574. .row-thumb { width: 56px; height: 56px; }
  575. .row-actions { grid-column: 1 / -1; }
  576. .row-actions .btn { flex: 1; }
  577. .seg { width: 100%; }
  578. .seg button { flex: 1; justify-content: center; padding: 0 8px; }
  579. .bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: grid; grid-template-columns: repeat(4, 1fr);
  580. padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: rgba(2, 4, 11, .94); border-top: 1px solid var(--line-strong);
  581. backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
  582. .bottom-nav button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; background: none; border: 0; color: var(--muted);
  583. font-size: 10.5px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
  584. .bottom-nav button .ic { width: 22px; height: 22px; }
  585. .bottom-nav button.active { color: var(--neon); text-shadow: var(--glow-text); }
  586. .bottom-nav button.active .ic { filter: drop-shadow(0 0 6px rgba(var(--neon-rgb), .9)); }
  587. .hud { gap: 8px; padding: 0 8px; }
  588. .hud .btn .lbl, .hud-timer .rec { display: none; }
  589. .hud .btn { width: 36px; padding: 0; }
  590. .hud-timer { padding: 0 8px; font-size: 12px; }
  591. .hud-hide-m { display: none !important; }
  592. .save-grid { grid-template-columns: 1fr; }
  593. .save-card { grid-template-columns: 84px minmax(0, 1fr); gap: 12px; }
  594. .sc-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  595. .src-legend .src { min-width: 0; }
  596. #hudSaveText { display: none; }
  597. .hud-save { padding: 0 9px; }
  598. .toasts { left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); align-items: stretch; }
  599. .toast { max-width: none; }
  600. }
  601. @media (max-width: 480px) {
  602. .seg button { gap: 5px; font-size: 12.5px; letter-spacing: .06em; padding: 0 4px; }
  603. .lib-bar .seg button .ic { display: none; }
  604. }
  605. @media (max-width: 420px) {
  606. .top-actions .btn:not(.keep) { display: none; }
  607. .hero h1 { font-size: 30px; }
  608. .hero-cta .btn { flex: 1; }
  609. }
  610. </style>
  611. </head>
  612. <body>
  613. <div class="bg" aria-hidden="true"><div class="horizon"></div><div class="floor"></div></div>
  614. <div class="vignette" aria-hidden="true"></div>
  615. <div class="scan" aria-hidden="true"></div>
  616.  
  617. <div class="app">
  618. <aside class="side">
  619. <button class="brand" data-go="home" title="Home">
  620. <span class="brand-mark"><i class="ic" data-ic="zap"></i></span>
  621. <span class="brand-text"><span class="logo glitch" data-text="GN-MATH">GN<b>-</b>MATH</span><span class="brand-sub">NEON ARCADE</span></span>
  622. </button>
  623. <div class="nav-label">NAVIGATE</div>
  624. <nav class="nav">
  625. <button class="nav-btn" data-go="home"><i class="ic" data-ic="home"></i>Home</button>
  626. <button class="nav-btn" data-go="games"><i class="ic" data-ic="grid"></i>All Games<span class="nav-count" id="navCountGames">—</span></button>
  627. <button class="nav-btn" data-go="library"><i class="ic" data-ic="library"></i>Library<span class="nav-count" id="navCountLib">0</span></button>
  628. </nav>
  629. <div class="nav-label">LIBRARY</div>
  630. <nav class="nav">
  631. <button class="nav-btn" data-go="library:recent" data-sub="recent"><i class="ic" data-ic="clock"></i>Recent<span class="nav-count" id="navCountRecent">0</span></button>
  632. <button class="nav-btn" data-go="library:favorites" data-sub="favorites"><i class="ic" data-ic="star"></i>Favorites<span class="nav-count" id="navCountFavs">0</span></button>
  633. <button class="nav-btn" data-go="library:saves" data-sub="saves"><i class="ic" data-ic="save"></i>Saves<span class="nav-count" id="navCountSaves">0</span></button>
  634. </nav>
  635. <div class="side-card">
  636. <h4>LOCAL STORAGE</h4>
  637. <div class="meter"><i id="sideMeter"></i></div>
  638. <div class="meter-text"><span id="sideUsage">—</span><span id="sideQuota"></span></div>
  639. </div>
  640. <div class="side-links">
  641. <button data-act="settings">Settings</button>
  642. <button data-act="dmca">DMCA</button>
  643. <button data-act="contact">Contact</button>
  644. <button data-act="privacy">Privacy</button>
  645. </div>
  646. </aside>
  647.  
  648. <div class="main">
  649. <header class="top">
  650. <button class="brand" data-go="home" title="Home">
  651. <span class="brand-mark"><i class="ic" data-ic="zap"></i></span>
  652. <span class="brand-text"><span class="logo">GN<b>-</b>MATH</span></span>
  653. </button>
  654. <div class="search">
  655. <i class="ic" data-ic="search"></i>
  656. <input type="text" id="searchBar" placeholder="Search games..." autocomplete="off" spellcheck="false" aria-label="Search games">
  657. <span class="kbd" id="searchKbd">/</span>
  658. <button class="search-clear hidden" id="searchClear" aria-label="Clear search"><i class="ic" data-ic="x"></i></button>
  659. </div>
  660. <div class="top-actions">
  661. <button class="btn" data-act="random" title="Play a random game"><i class="ic" data-ic="shuffle"></i><span class="lbl">Random</span></button>
  662. <button class="btn icon" id="refresh" data-act="refresh" title="Refresh all the games"><i class="ic" data-ic="refresh"></i></button>
  663. <button class="btn icon keep" id="settings" data-act="settings" title="Settings"><i class="ic" data-ic="settings"></i></button>
  664. </div>
  665. </header>
  666.  
  667. <main class="view" id="view" aria-live="polite"></main>
  668. </div>
  669. </div>
  670.  
  671. <nav class="bottom-nav">
  672. <button data-go="home"><i class="ic" data-ic="home"></i>Home</button>
  673. <button data-go="games"><i class="ic" data-ic="grid"></i>Games</button>
  674. <button data-go="library"><i class="ic" data-ic="library"></i>Library</button>
  675. <button data-act="settings"><i class="ic" data-ic="settings"></i>Settings</button>
  676. </nav>
  677.  
  678. <div id="zoneViewer" role="dialog" aria-modal="true" aria-labelledby="zoneName">
  679. <div class="hud">
  680. <button class="btn icon" data-act="close" title="Back to games"><i class="ic" data-ic="chevron-left"></i></button>
  681. <div class="hud-title">
  682. <div>
  683. <h2 id="zoneName">zone</h2>
  684. <a id="zoneAuthor" href="#" target="_blank" rel="noopener">by Author</a>
  685. </div>
  686. </div>
  687. <span id="zoneId" hidden></span>
  688. <div class="hud-timer" title="Session time"><span class="rec"></span><span id="hudTimer">00:00</span></div>
  689. <button class="hud-save hidden" id="hudSave" data-act="hud-save"><i class="ic" data-ic="save"></i><span id="hudSaveText"></span></button>
  690. <div class="hud-actions">
  691. <button class="btn icon" id="hudFav" data-act="hud-fav" title="Favorite"><i class="ic" data-ic="star"></i></button>
  692. <button class="btn icon hud-hide-m" data-act="info" title="Game info"><i class="ic" data-ic="info"></i></button>
  693. <button class="btn" data-act="fullscreen" title="Fullscreen"><i class="ic" data-ic="maximize"></i><span class="lbl">Fullscreen</span></button>
  694. <button class="btn hud-hide-m" data-act="newtab" title="Open in new tab"><i class="ic" data-ic="external"></i><span class="lbl">New Tab</span></button>
  695. <button class="btn icon hud-hide-m" data-act="download" title="Download"><i class="ic" data-ic="download"></i></button>
  696. <button class="btn icon danger" data-act="close" title="Close"><i class="ic" data-ic="x"></i></button>
  697. </div>
  698. </div>
  699. <div class="stage" id="stage">
  700. <div class="loader" id="loader"><div class="loader-box"><div class="loader-ring"></div>LOADING<div class="loader-name" id="loaderName"></div></div></div>
  701. </div>
  702. </div>
  703.  
  704. <div id="popupOverlay">
  705. <div class="popup" id="popup">
  706. <div class="popup-in">
  707. <div class="popup-header">
  708. <h3 id="popupTitle">Title</h3>
  709. <button class="btn icon sm" id="popupClose" data-act="popup-close" aria-label="Close"><i class="ic" data-ic="x"></i></button>
  710. </div>
  711. <div id="popupBody"></div>
  712. </div>
  713. </div>
  714. </div>
  715.  
  716. <div class="toasts" id="toasts"></div>
  717. <input type="file" id="importData" accept=".data,.json,application/json,application/octet-stream" hidden>
  718.  
  719. <script>
  720. /* ================= icons ================= */
  721. // Inline SVG, not <use href="#...">: the <base> tag above would point fragment refs at jsDelivr.
  722. const ICONS = {
  723. zap: '<path d="M13 2 3 14h9l-1 8 10-12h-9z"/>',
  724. home: '<path d="M3 10.5 12 3l9 7.5V20a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z"/>',
  725. grid: '<rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/>',
  726. library: '<rect x="3" y="3" width="5" height="18"/><rect x="10" y="3" width="5" height="18"/><path d="m17 4.5 3.6-1 2.4 16.6-3.6 1z"/>',
  727. clock: '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>',
  728. star: '<polygon points="12 2.5 15 8.6 21.7 9.6 16.8 14.3 18 21 12 17.8 6 21 7.2 14.3 2.3 9.6 9 8.6"/>',
  729. save: '<path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><path d="M17 21v-8H7v8M7 3v5h8"/>',
  730. search: '<circle cx="11" cy="11" r="7"/><path d="m20 20-3.6-3.6"/>',
  731. refresh: '<path d="M21 12a9 9 0 1 1-2.64-6.36L21 8"/><path d="M21 3v5h-5"/>',
  732. settings: '<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"/>',
  733. shuffle: '<path d="M16 3h5v5M4 20 21 3M21 16v5h-5M15 15l6 6M4 4l5 5"/>',
  734. x: '<path d="M18 6 6 18M6 6l12 12"/>',
  735. play: '<polygon points="6 3 20 12 6 21"/>',
  736. info: '<circle cx="12" cy="12" r="9"/><path d="M12 16v-5M12 8h.01"/>',
  737. maximize: '<path d="M8 3H5a2 2 0 0 0-2 2v3M21 8V5a2 2 0 0 0-2-2h-3M3 16v3a2 2 0 0 0 2 2h3M16 21h3a2 2 0 0 0 2-2v-3"/>',
  738. external: '<path d="M15 3h6v6M10 14 21 3M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>',
  739. download: '<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5M12 15V3"/>',
  740. upload: '<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M17 8l-5-5-5 5M12 3v12"/>',
  741. trash: '<path d="M3 6h18M8 6V4h8v2M19 6l-1 14H6L5 6M10 11v6M14 11v6"/>',
  742. 'chevron-left': '<path d="m15 18-6-6 6-6"/>',
  743. 'chevron-right': '<path d="m9 18 6-6-6-6"/>',
  744. eye: '<path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>',
  745. database: '<ellipse cx="12" cy="5" rx="8" ry="3"/><path d="M4 5v14c0 1.7 3.6 3 8 3s8-1.3 8-3V5M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3"/>',
  746. gamepad: '<path d="M6 12h4M8 10v4M15 13h.01M18 11h.01"/><rect x="2" y="6" width="20" height="12" rx="4"/>',
  747. check: '<path d="M20 6 9 17l-5-5"/>',
  748. alert: '<path d="M12 3 2 21h20zM12 10v4M12 17.5h.01"/>',
  749. trend: '<path d="m3 17 6-6 4 4 8-8M15 7h6v6"/>',
  750. link: '<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/>',
  751. sparkle: '<path d="M12 3v4M12 17v4M3 12h4M17 12h4M6 6l2.5 2.5M15.5 15.5 18 18M6 18l2.5-2.5M15.5 8.5 18 6"/>'
  752. };
  753. function ic(name) {
  754. return `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${ICONS[name] || ''}</svg>`;
  755. }
  756. function hydrateIcons(root = document) {
  757. root.querySelectorAll('[data-ic]').forEach(el => { el.innerHTML = ic(el.dataset.ic); el.removeAttribute('data-ic'); });
  758. }
  759. hydrateIcons();
  760.  
  761. /* ================= state ================= */
  762. const store = {
  763. get(k, d) { try { const v = localStorage.getItem(k); return v == null ? d : JSON.parse(v); } catch (e) { return d; } },
  764. set(k, v) { try { localStorage.setItem(k, JSON.stringify(v)); } catch (e) {} }
  765. };
  766. const PREFIX = 'gnx:';
  767. const K = { recent: PREFIX + 'recent', favs: PREFIX + 'favs', saves: PREFIX + 'saves', settings: PREFIX + 'settings' };
  768. let recent, favs, saves, settings;
  769. function loadState() {
  770. recent = store.get(K.recent, []); // [{ id, last, total, sessions }]
  771. favs = store.get(K.favs, []); // [id] newest first
  772. saves = store.get(K.saves, {}); // { id: { keys: [], dbs: [], first, updated } }
  773. settings = Object.assign({ accent: 'blue', scan: true, motion: true, size: 'm', confirmLeave: true, cloakTitle: '', cloakIcon: '' }, store.get(K.settings, {}));
  774. }
  775. loadState();
  776. const saveRecent = () => store.set(K.recent, recent);
  777. const saveFavs = () => store.set(K.favs, favs);
  778. const saveSaves = () => store.set(K.saves, saves);
  779. const saveSettings = () => store.set(K.settings, settings);
  780.  
  781. const view = document.getElementById('view');
  782. const zoneViewer = document.getElementById('zoneViewer');
  783. const stage = document.getElementById('stage');
  784. const loader = document.getElementById('loader');
  785. let zoneFrame = null;
  786. const searchBar = document.getElementById('searchBar');
  787.  
  788. const zonesurls = [
  789. ];
  790. let zonesURL = zonesurls[Math.floor(Math.random() * zonesurls.length)];
  791. let zones = [];
  792. let zoneMap = new Map();
  793. let popularityData = {};
  794. let allTags = [];
  795. let newIds = new Set();
  796. let loadState_ = 'loading'; // loading | ready | error
  797. let loadError = '';
  798.  
  799. const ui = { view: 'home', sub: 'recent', tag: 'none', sort: store.get(PREFIX + 'sort', 'popular'), query: '' };
  800. let currentZone = null;
  801.  
  802. /* ================= helpers ================= */
  803. const esc = s => String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
  804. const fill = u => String(u || '').replace("{COVER_URL}", coverURL).replace("{HTML_URL}", htmlURL);
  805. const byId = id => zoneMap.get(String(id));
  806. const isExternal = z => String(z.url || '').startsWith('http');
  807. const compact = new Intl.NumberFormat('en', { notation: 'compact', maximumFractionDigits: 1 });
  808. function toTitleCase(str) {
  809. return str.replace(/\w\S*/g, text => text.charAt(0).toUpperCase() + text.substring(1).toLowerCase());
  810. }
  811. function fmtDur(ms) {
  812. const m = Math.floor(ms / 60000);
  813. if (m < 1) return ms > 0 ? '<1m' : '0m';
  814. const h = Math.floor(m / 60);
  815. return h ? `${h}h ${m % 60}m` : `${m}m`;
  816. }
  817. function fmtClock(ms) {
  818. const s = Math.floor(ms / 1000), h = Math.floor(s / 3600), m = Math.floor(s / 60) % 60, ss = s % 60;
  819. const p = n => String(n).padStart(2, '0');
  820. return h ? `${h}:${p(m)}:${p(ss)}` : `${p(m)}:${p(ss)}`;
  821. }
  822. function ago(t) {
  823. if (!t) return 'never';
  824. const s = (Date.now() - t) / 1000;
  825. if (s < 60) return 'just now';
  826. if (s < 3600) return `${Math.floor(s / 60)}m ago`;
  827. if (s < 86400) return `${Math.floor(s / 3600)}h ago`;
  828. if (s < 86400 * 30) return `${Math.floor(s / 86400)}d ago`;
  829. return new Date(t).toLocaleDateString();
  830. }
  831. function fmtBytes(b) {
  832. if (!b) return '0 B';
  833. const u = ['B', 'KB', 'MB', 'GB'];
  834. const i = Math.min(u.length - 1, Math.floor(Math.log(b) / Math.log(1024)));
  835. return `${(b / Math.pow(1024, i)).toFixed(i ? 1 : 0)} ${u[i]}`;
  836. }
  837. function plays(z, period = 'year') { return popularityData[period]?.[z.id] ?? 0; }
  838.  
  839. function toast(msg, kind = '', opts = {}) {
  840. const el = document.createElement('div');
  841. el.className = `toast ${kind}`;
  842. el.innerHTML = `<i class="ic">${ic(kind === 'err' ? 'alert' : kind === 'ok' ? 'check' : 'info')}</i><span>${esc(msg)}</span>`;
  843. if (opts.action) {
  844. const b = document.createElement('button');
  845. b.className = 'btn sm';
  846. b.textContent = opts.action.label;
  847. b.onclick = () => { opts.action.run(); el.remove(); };
  848. el.appendChild(b);
  849. }
  850. document.getElementById('toasts').appendChild(el);
  851. setTimeout(() => { el.classList.add('out'); setTimeout(() => el.remove(), 320); }, opts.ms || 3600);
  852. return el;
  853. }
  854.  
  855. /* ================= settings application ================= */
  856. function applySettings() {
  857. const r = document.documentElement;
  858. r.dataset.accent = settings.accent;
  859. r.dataset.scan = settings.scan ? 'on' : 'off';
  860. r.dataset.motion = settings.motion ? 'on' : 'off';
  861. r.dataset.size = settings.size;
  862. if (settings.cloakTitle) cloakName(settings.cloakTitle);
  863. if (settings.cloakIcon) cloakIcon(settings.cloakIcon);
  864. }
  865. applySettings();
  866.  
  867. window.addEventListener('beforeunload', function (event) {
  868. flushTracking();
  869. if (!settings.confirmLeave) return;
  870. event.preventDefault();
  871. event.returnValue = '';
  872. return 'Are you sure you want to leave? Any unsaved changes will be lost.';
  873. });
  874. window.addEventListener('pagehide', flushTracking);
  875.  
  876. /* ================= loading ================= */
  877. async function listZones() {
  878. const refreshBtn = document.getElementById('refresh');
  879. refreshBtn.classList.add('spin');
  880. try {
  881. let sharesponse;
  882. let shajson;
  883. let sha;
  884. try {
  885. sharesponse = await fetch("https://api.github.com/repos/freebuisness/assets/commits?t="; + Date.now());
  886. } catch (error) {}
  887. if (sharesponse && sharesponse.status === 200) {
  888. try {
  889. shajson = await sharesponse.json();
  890. sha = shajson[0]['sha'];
  891. if (sha) {
  892. }
  893. } catch (error) {
  894. try {
  895. let secondarysharesponse = await fetch("https://raw.githubusercontent.com/freebuisness/xml/refs/heads/main/sha.txt?t="; + Date.now());
  896. if (secondarysharesponse && secondarysharesponse.status === 200) {
  897. sha = (await secondarysharesponse.text()).trim();
  898. if (sha) {
  899. }
  900. }
  901. } catch (error) {}
  902. }
  903. }
  904. const response = await fetch(zonesURL + "?t=" + Date.now());
  905. const json = await response.json();
  906. zones = json;
  907. zones[0].featured = true; // always gonna be the discord
  908. zoneMap = new Map(zones.map(z => [String(z.id), z]));
  909. newIds = new Set([...zones].filter(z => z.id > 0).sort((a, b) => b.id - a.id).slice(0, 24).map(z => String(z.id)));
  910.  
  911. let alltags = [];
  912. for (const obj of json) {
  913. if (Array.isArray(obj.special)) alltags.push(...obj.special);
  914. }
  915. const tagCounts = {};
  916. alltags.forEach(t => tagCounts[t] = (tagCounts[t] || 0) + 1);
  917. allTags = [...new Set(alltags)].sort((a, b) => tagCounts[b] - tagCounts[a]).map(t => ({ tag: t, n: tagCounts[t] }));
  918.  
  919. loadState_ = 'ready';
  920. nameIndex = null;
  921. render();
  922. autoDetect().then(changed => { if (changed) render(); });
  923. Promise.all([fetchPopularity("year"), fetchPopularity("month"), fetchPopularity("week"), fetchPopularity("day")]).then(render);
  924.  
  925. try {
  926. const search = new URLSearchParams(window.location.search);
  927. const id = search.get('id');
  928. const embed = window.location.hash.includes("embed");
  929. if (id) {
  930. const zone = zones.find(zone => zone.id + '' == id + '');
  931. if (zone) {
  932. if (embed) embedZone(zone);
  933. else openZone(zone);
  934. }
  935. }
  936. } catch (error) {}
  937. } catch (error) {
  938. console.error(error);
  939. loadState_ = 'error';
  940. loadError = String(error);
  941. render();
  942. } finally {
  943. refreshBtn.classList.remove('spin');
  944. }
  945. }
  946.  
  947. function embedZone(zone) {
  948. if (zone.url.startsWith("http")) {
  949. window.open(zone.url, "_blank");
  950. return;
  951. }
  952. const url = fill(zone.url);
  953. fetch(url + "?t=" + Date.now()).then(response => response.text()).then(html => {
  954. document.documentElement.innerHTML = html;
  955. const popup = document.createElement("div");
  956. popup.style.cssText = "position:fixed;bottom:20px;right:20px;background:#04101f;color:#bfefff;padding:10px 14px;border:1px solid #00d4ff;box-shadow:0 0 18px rgba(0,212,255,.45);font-family:Arial,sans-serif;z-index:2147483647";
  957. popup.innerHTML = `Play more games at <a href="https://gn-math.dev"; target="_blank" style="color:#00d4ff;font-weight:bold;">https://gn-math.dev</a>!`;
  958. const closeBtn = document.createElement("button");
  959. closeBtn.innerText = "Ă—";
  960. closeBtn.style.cssText = "margin-left:10px;background:none;border:none;cursor:pointer;color:#00d4ff;font-weight:bold;font-size:16px";
  961. closeBtn.onclick = () => popup.remove();
  962. popup.appendChild(closeBtn);
  963. document.body.appendChild(popup);
  964. document.documentElement.querySelectorAll('script').forEach(oldScript => {
  965. const newScript = document.createElement('script');
  966. if (oldScript.src) newScript.src = oldScript.src;
  967. else newScript.textContent = oldScript.textContent;
  968. document.body.appendChild(newScript);
  969. });
  970. }).catch(error => alert("Failed to load zone: " + error));
  971. }
  972.  
  973. async function fetchPopularity(duration) {
  974. try {
  975. if (!popularityData[duration]) popularityData[duration] = {};
  976. const data = await response.json();
  977. data.forEach(file => {
  978. const idMatch = file.name.match(/\/(\d+)\.html$/);
  979. if (idMatch) {
  980. const id = parseInt(idMatch[1]);
  981. popularityData[duration][id] = file.hits?.total ?? 0;
  982. }
  983. });
  984. } catch (error) {
  985. if (!popularityData[duration]) popularityData[duration] = {};
  986. popularityData[duration][0] = 0;
  987. }
  988. }
  989.  
  990. /* ================= sorting / filtering ================= */
  991. function sortList(list, sortBy = ui.sort) {
  992. const out = [...list];
  993. const byPop = p => (a, b) => (popularityData[p]?.[b.id] ?? 0) - (popularityData[p]?.[a.id] ?? 0);
  994. if (sortBy === 'name') out.sort((a, b) => a.name.localeCompare(b.name));
  995. else if (sortBy === 'id') out.sort((a, b) => a.id - b.id);
  996. else if (sortBy === 'newest') out.sort((a, b) => b.id - a.id);
  997. else if (sortBy === 'popular') out.sort(byPop('year'));
  998. else if (sortBy === 'trendingMonth') out.sort(byPop('month'));
  999. else if (sortBy === 'trendingWeek') out.sort(byPop('week'));
  1000. else if (sortBy === 'trendingDay') out.sort(byPop('day'));
  1001. out.sort((a, b) => (a.id === -1 ? -1 : b.id === -1 ? 1 : 0));
  1002. return out;
  1003. }
  1004. function filteredZones() {
  1005. const q = ui.query.trim().toLowerCase();
  1006. let list = zones;
  1007. if (ui.tag !== 'none') list = list.filter(z => z.special?.includes(ui.tag));
  1008. if (q) list = list.filter(z => z.name.toLowerCase().includes(q) || (z.author || '').toLowerCase().includes(q));
  1009. return sortList(list);
  1010. }
  1011. // kept for anything that still calls the old names
  1012. function sortZones() { render(); }
  1013. function filterZones() { ui.query = searchBar.value; go('games'); }
  1014. function filterZones2() { render(); }
  1015.  
  1016. /* ================= cards ================= */
  1017. function cardHTML(z) {
  1018. const id = String(z.id);
  1019. const tag = Array.isArray(z.special) && z.special.length ? z.special[0] : '';
  1020. const p = plays(z);
  1021. const badges = [
  1022. saves[id] ? '<span class="badge save">SAVE</span>' : '',
  1023. isExternal(z) ? '<span class="badge ext">LINK</span>' : '',
  1024. newIds.has(id) ? '<span class="badge new">NEW</span>' : ''
  1025. ].join('');
  1026. const fav = favs.includes(id);
  1027. return `<article class="card" data-open="${esc(id)}" tabindex="0" title="${esc(z.name)}">
  1028. <div class="card-frame"><div class="card-body">
  1029. <div class="cover">
  1030. <img alt="" data-src="${esc(fill(z.cover))}">
  1031. <span class="sweep"></span>
  1032. <div class="badges">${badges}</div>
  1033. <button class="fav${fav ? ' on' : ''}" data-fav="${esc(id)}" aria-label="${fav ? 'Remove from' : 'Add to'} favorites">${ic('star')}</button>
  1034. <div class="play-hint"><i class="ic">${ic('play')}</i></div>
  1035. </div>
  1036. <div class="meta">
  1037. <h3>${esc(z.name)}</h3>
  1038. <div class="sub">${tag ? `<span class="tag">${esc(tag)}</span>` : `<span class="tag">#${esc(id)}</span>`}${p ? `<span class="plays"><i class="ic">${ic('play')}</i>${compact.format(p)}</span>` : ''}</div>
  1039. </div>
  1040. </div></div>
  1041. </article>`;
  1042. }
  1043. const imageObserver = new IntersectionObserver((entries, observer) => {
  1044. entries.forEach(entry => {
  1045. if (!entry.isIntersecting) return;
  1046. const img = entry.target;
  1047. img.onload = () => img.classList.add('loaded');
  1048. img.onerror = () => img.classList.add('err');
  1049. img.src = img.dataset.src;
  1050. observer.unobserve(img);
  1051. });
  1052. }, { rootMargin: "300px 300px" });
  1053. function observeImages(root) {
  1054. root.querySelectorAll('img[data-src]:not([src])').forEach(img => imageObserver.observe(img));
  1055. }
  1056. function skeletons(n) { return Array.from({ length: n }, () => '<div class="skeleton"></div>').join(''); }
  1057.  
  1058. function emptyState(icon, title, text, cta = '') {
  1059. return `<div class="empty"><div><div class="big" style="margin-inline:auto"><i class="ic">${ic(icon)}</i></div><h3>${esc(title)}</h3><p>${text}</p>${cta}</div></div>`;
  1060. }
  1061.  
  1062. /* ================= navigation ================= */
  1063. function go(target) {
  1064. const [v, sub] = String(target).split(':');
  1065. ui.view = v;
  1066. if (sub) ui.sub = sub;
  1067. render();
  1068. window.scrollTo(0, 0);
  1069. }
  1070. function updateNav() {
  1071. document.querySelectorAll('[data-go]').forEach(b => {
  1072. const [v, sub] = b.dataset.go.split(':');
  1073. const active = sub ? (ui.view === 'library' && ui.sub === sub) : (ui.view === v && (v !== 'library' || !b.closest('.side')));
  1074. b.classList.toggle('active', active && !b.classList.contains('brand'));
  1075. });
  1076. const totalSaves = Object.keys(saves).length;
  1077. document.getElementById('navCountGames').textContent = zones.length || '—';
  1078. document.getElementById('navCountRecent').textContent = recent.length;
  1079. document.getElementById('navCountFavs').textContent = favs.length;
  1080. document.getElementById('navCountSaves').textContent = totalSaves;
  1081. document.getElementById('navCountLib').textContent = recent.length + favs.length;
  1082. }
  1083.  
  1084. function render() {
  1085. updateNav();
  1086. if (ui.view === 'games') renderGames();
  1087. else if (ui.view === 'library') renderLibrary();
  1088. else renderHome();
  1089. observeImages(view);
  1090. updateStorageMeter();
  1091. }
  1092.  
  1093. /* ================= home ================= */
  1094. function railHTML(list) {
  1095. return `<div class="rail-wrap"><button class="rail-btn l" data-rail="-1" aria-label="Scroll left">${ic('chevron-left')}</button>
  1096. <div class="rail">${list.map(cardHTML).join('')}</div>
  1097. <button class="rail-btn r" data-rail="1" aria-label="Scroll right">${ic('chevron-right')}</button></div>`;
  1098. }
  1099. function sectionHTML(idx, title, body, link) {
  1100. return `<section class="section"><div class="section-head"><span class="section-idx">${idx}</span><h2>${title}</h2><span class="rule"></span>${link ? `<button class="link" data-go="${link}">View all →</button>` : ''}</div>${body}</section>`;
  1101. }
  1102. function renderHome() {
  1103. const totalTime = recent.reduce((a, r) => a + (r.total || 0), 0);
  1104. const last = recent.map(r => ({ r, z: byId(r.id) })).find(x => x.z && !isExternal(x.z));
  1105. const ready = loadState_ === 'ready';
  1106. const continueHTML = last ? `
  1107. <button class="continue" data-open="${esc(last.z.id)}">
  1108. <img src="${esc(fill(last.z.cover))}" alt="">
  1109. <div><div class="c-label">CONTINUE</div><div class="c-name">${esc(last.z.name)}</div><div class="c-meta">${ago(last.r.last)} · ${fmtDur(last.r.total)} played</div></div>
  1110. <span class="play-dot"></span>
  1111. </button>` : '';
  1112. let html = `
  1113. <section class="hero">
  1114. <div class="hero-art" style="${last ? `background-image:url('${esc(fill(last.z.cover))}')` : ''}"></div>
  1115. <span class="hero-corner tl"></span><span class="hero-corner br"></span>
  1116. <div>
  1117. <div class="eyebrow"><span class="dot"></span>${ready ? `SYSTEM ONLINE // ${zones.length} GAMES LOADED` : loadState_ === 'error' ? 'LINK DOWN // RETRY' : 'CONNECTING // FETCHING GAMES'}</div>
  1118. <h1>Jack in.<br><span class="accent">Play anything.</span></h1>
  1119. <p>Hundreds of browser games, no downloads. Your recent games, favorites and save data are tracked in the Library, right on this device.</p>
  1120. <div class="hero-cta">
  1121. <button class="btn primary" data-go="games"><i class="ic">${ic('grid')}</i>Browse games</button>
  1122. <button class="btn" data-act="random"><i class="ic">${ic('shuffle')}</i>Random game</button>
  1123. </div>
  1124. ${continueHTML}
  1125. </div>
  1126. <div class="stats">
  1127. <div class="stat"><div class="stat-k">Games</div><div class="stat-v">${ready ? zones.length : '—'}</div></div>
  1128. <div class="stat"><div class="stat-k">Played</div><div class="stat-v">${recent.length}</div></div>
  1129. <div class="stat"><div class="stat-k">Playtime</div><div class="stat-v">${fmtDur(totalTime)}</div></div>
  1130. <div class="stat"><div class="stat-k">Saves</div><div class="stat-v">${Object.keys(saves).length}</div></div>
  1131. </div>
  1132. </section>`;
  1133.  
  1134. if (loadState_ === 'loading') {
  1135. html += sectionHTML('01', 'Loading', `<div class="grid">${skeletons(12)}</div>`);
  1136. } else if (loadState_ === 'error') {
  1137. html += `<div class="section">${emptyState('alert', 'Could not load games', `Error loading zones: ${esc(loadError)}`, `<button class="btn primary" data-act="refresh"><i class="ic">${ic('refresh')}</i>Try again</button>`)}</div>`;
  1138. } else {
  1139. let n = 1;
  1140. const idx = () => String(n++).padStart(2, '0');
  1141. const rec = recent.map(r => byId(r.id)).filter(Boolean).slice(0, 14);
  1142. if (rec.length) html += sectionHTML(idx(), 'Recently played', railHTML(rec), 'library:recent');
  1143. const fav = favs.map(byId).filter(Boolean).slice(0, 14);
  1144. if (fav.length) html += sectionHTML(idx(), 'Favorites', railHTML(fav), 'library:favorites');
  1145. const featured = zones.filter(z => z.featured);
  1146. if (featured.length) html += sectionHTML(idx(), 'Featured', railHTML(featured));
  1147. const trending = sortList(zones.filter(z => z.id >= 0 && !isExternal(z)), 'trendingWeek').slice(0, 16);
  1148. html += sectionHTML(idx(), 'Trending this week', railHTML(trending), 'games');
  1149. const fresh = sortList(zones.filter(z => z.id >= 0), 'newest').slice(0, 16);
  1150. html += sectionHTML(idx(), 'New arrivals', railHTML(fresh), 'games');
  1151. const top = sortList(zones.filter(z => z.id >= 0 && !isExternal(z)), 'popular').slice(0, 24);
  1152. html += sectionHTML(idx(), 'All-time top', `<div class="grid">${top.map(cardHTML).join('')}</div>`, 'games');
  1153. }
  1154. view.innerHTML = html;
  1155. }
  1156.  
  1157. /* ================= all games ================= */
  1158. function renderGames() {
  1159. const list = loadState_ === 'ready' ? filteredZones() : [];
  1160. const sortOpts = [['popular', 'Popular'], ['trendingDay', 'Trending (Day)'], ['trendingWeek', 'Trending (Week)'], ['trendingMonth', 'Trending (Month)'], ['newest', 'Newest'], ['id', 'Oldest (ID)'], ['name', 'Name A–Z']];
  1161. const chips = [`<button class="chip${ui.tag === 'none' ? ' on' : ''}" data-tag="none">All<span class="n">${zones.length}</span></button>`]
  1162. .concat(allTags.map(t => `<button class="chip${ui.tag === t.tag ? ' on' : ''}" data-tag="${esc(t.tag)}">${esc(toTitleCase(t.tag))}<span class="n">${t.n}</span></button>`)).join('');
  1163. let body;
  1164. if (loadState_ === 'loading') body = `<div class="grid">${skeletons(24)}</div>`;
  1165. else if (loadState_ === 'error') body = emptyState('alert', 'Could not load games', `Error loading zones: ${esc(loadError)}`, `<button class="btn primary" data-act="refresh">Try again</button>`);
  1166. else if (!list.length) body = emptyState('search', 'No games found', `Nothing matches <b>${esc(ui.query)}</b>${ui.tag !== 'none' ? ` in <b>${esc(toTitleCase(ui.tag))}</b>` : ''}.`, `<button class="btn" data-act="clear-filters">Clear filters</button>`);
  1167. else body = `<div class="grid" id="container">${list.map(cardHTML).join('')}</div>`;
  1168.  
  1169. view.innerHTML = `
  1170. <div class="page-head">
  1171. <div><div class="eyebrow">ARCADE // INDEX</div><h1>All <span class="accent">Games</span></h1></div>
  1172. <div class="count">SHOWING <b>${list.length}</b> / ${zones.length || '—'}</div>
  1173. </div>
  1174. <div class="toolbar">
  1175. <div class="chips">${chips}</div>
  1176. <label class="select" title="Sort">
  1177. <select id="sortOptions" aria-label="Sort games">${sortOpts.map(([v, l]) => `<option value="${v}"${ui.sort === v ? ' selected' : ''}>${l}</option>`).join('')}</select>
  1178. <i class="ic">${ic('chevron-right')}</i>
  1179. </label>
  1180. </div>
  1181. ${body}`;
  1182. document.getElementById('sortOptions').onchange = e => { ui.sort = e.target.value; store.set(PREFIX + 'sort', ui.sort); render(); };
  1183. }
  1184.  
  1185. /* ================= library ================= */
  1186. function renderLibrary() {
  1187. const savesCount = Object.keys(saves).length;
  1188. const seg = [['recent', 'clock', 'Recent', recent.length], ['favorites', 'star', 'Favorites', favs.length], ['saves', 'save', 'Saves', savesCount]]
  1189. .map(([k, i, l, n]) => `<button class="${ui.sub === k ? 'on' : ''}" data-go="library:${k}"><i class="ic">${ic(i)}</i>${l}<span class="n">${n}</span></button>`).join('');
  1190. let body = '';
  1191. if (ui.sub === 'favorites') body = renderFavorites();
  1192. else if (ui.sub === 'saves') body = renderSaves();
  1193. else body = renderRecent();
  1194. view.innerHTML = `
  1195. <div class="page-head">
  1196. <div><div class="eyebrow">USER // LIBRARY</div><h1>Your <span class="accent">Library</span></h1></div>
  1197. </div>
  1198. <div class="lib-bar"><div class="seg">${seg}</div><span class="spacer"></span>${libActions()}</div>
  1199. ${body}`;
  1200. if (ui.sub === 'saves') {
  1201. fillSaveSizes();
  1202. if (!detecting) {
  1203. detecting = true;
  1204. autoDetect().then(changed => {
  1205. detecting = false;
  1206. if (changed && ui.view === 'library' && ui.sub === 'saves') render();
  1207. });
  1208. }
  1209. }
  1210. }
  1211. function libActions() {
  1212. if (ui.sub === 'recent' && recent.length) return `<button class="btn sm danger" data-act="clear-recent"><i class="ic">${ic('trash')}</i>Clear history</button>`;
  1213. if (ui.sub === 'saves') return `<button class="btn sm" data-act="export"><i class="ic">${ic('download')}</i>Export all</button><button class="btn sm" data-act="import"><i class="ic">${ic('upload')}</i>Import</button>`;
  1214. return '';
  1215. }
  1216. function needZones() {
  1217. if (loadState_ === 'loading') return `<div class="grid">${skeletons(8)}</div>`;
  1218. return '';
  1219. }
  1220. function renderRecent() {
  1221. if (!recent.length) return emptyState('clock', 'Nothing played yet', 'Games you open show up here with when you last played them and how long you have played in total.', `<button class="btn primary" data-go="games">Browse games</button>`);
  1222. const wait = needZones(); if (wait) return wait;
  1223. return `<div class="list">${recent.map(r => {
  1224. const z = byId(r.id);
  1225. if (!z) return '';
  1226. const s = saves[String(z.id)];
  1227. return `<div class="row">
  1228. <img class="row-thumb" src="${esc(fill(z.cover))}" alt="" data-open="${esc(z.id)}" loading="lazy">
  1229. <div class="row-main">
  1230. <div class="row-title" data-open="${esc(z.id)}">${esc(z.name)}</div>
  1231. <div class="row-meta">
  1232. <span class="when"><i class="ic">${ic('clock')}</i>${ago(r.last)}</span>
  1233. <span><i class="ic">${ic('gamepad')}</i>${fmtDur(r.total || 0)} total</span>
  1234. <span>${r.sessions || 1} session${(r.sessions || 1) === 1 ? '' : 's'}</span>
  1235. ${s ? `<button class="link-save" data-act="save-details" data-id="${esc(z.id)}"><i class="ic">${ic('save')}</i>save${(s.keys || []).length ? ' · ' + fmtBytes(lsBytes(s.keys)) : ''}${s.updated ? ' · ' + ago(s.updated) : ''}</button>` : ''}
  1236. </div>
  1237. </div>
  1238. <div class="row-actions">
  1239. <button class="btn sm primary" data-open="${esc(z.id)}"><i class="ic">${ic('play')}</i>Play</button>
  1240. <button class="btn sm icon" data-fav="${esc(z.id)}" title="Favorite" style="${favs.includes(String(z.id)) ? 'color:var(--warn)' : ''}">${ic('star')}</button>
  1241. <button class="btn sm icon" data-act="forget" data-id="${esc(z.id)}" title="Remove from history">${ic('x')}</button>
  1242. </div>
  1243. </div>`;
  1244. }).join('')}</div>`;
  1245. }
  1246. function renderFavorites() {
  1247. if (!favs.length) return emptyState('star', 'No favorites yet', 'Hit the star on any game card or in the game bar to pin it here.', `<button class="btn primary" data-go="games">Browse games</button>`);
  1248. const wait = needZones(); if (wait) return wait;
  1249. return `<div class="grid">${favs.map(byId).filter(Boolean).map(cardHTML).join('')}</div>`;
  1250. }
  1251.  
  1252. /* ---- save data ---- */
  1253. function lsBytes(keys) {
  1254. let n = 0;
  1255. for (const k of keys) { const v = localStorage.getItem(k); if (v != null) n += (k.length + v.length) * 2; }
  1256. return n;
  1257. }
  1258. function ownedKeys() {
  1259. const s = new Set();
  1260. Object.values(saves).forEach(e => (e.keys || []).forEach(k => s.add(k)));
  1261. return s;
  1262. }
  1263. function unassignedKeys() {
  1264. const owned = ownedKeys();
  1265. const out = [];
  1266. for (let i = 0; i < localStorage.length; i++) {
  1267. const k = localStorage.key(i);
  1268. if (k && !k.startsWith(PREFIX) && !owned.has(k)) out.push(k);
  1269. }
  1270. return out;
  1271. }
  1272. function pruneSaves() {
  1273. // drop keys that no longer exist so the list reflects reality
  1274. let changed = false;
  1275. for (const [id, e] of Object.entries(saves)) {
  1276. const keys = (e.keys || []).filter(k => localStorage.getItem(k) !== null);
  1277. if (keys.length !== (e.keys || []).length) { e.keys = keys; changed = true; }
  1278. if (!keys.length && !(e.dbs || []).length) { delete saves[id]; changed = true; }
  1279. }
  1280. if (changed) saveSaves();
  1281. }
  1282. /* ---- linking saves to games ---- */
  1283. const SRC = { tracked: ['SEEN WHILE PLAYING', 'ok'], manual: ['LINKED BY YOU', 'manual'], detected: ['AUTO-MATCHED', 'auto'] };
  1284. const SRC_RANK = { detected: 0, manual: 1, tracked: 2 };
  1285. const isCacheDb = n => /cache/i.test(n); // engine asset caches (UnityCache etc.), not progress
  1286. const norm = s => String(s || '').toLowerCase().replace(/[^a-z0-9]/g, '');
  1287. let nameIndex = null;
  1288. function guessGame(storageName) {
  1289. if (!zones.length) return null;
  1290. if (!nameIndex) {
  1291. nameIndex = zones.filter(z => z.id >= 0 && !isExternal(z)).map(z => {
  1292. const base = z.name.replace(/\(.*?\)|\[.*?\]/g, ' ');
  1293. const names = new Set([norm(base), norm(base.replace(/\s*v?[\d.]+\s*$/i, '')), norm(base.replace(/^the\s+/i, ''))]);
  1294. return { z, names: [...names].filter(n => n.length >= 4) };
  1295. });
  1296. }
  1297. const n = norm(storageName);
  1298. if (n.length < 4) return null;
  1299. let best = null, bestLen = 0;
  1300. for (const { z, names } of nameIndex) for (const nm of names) if (nm.length > bestLen && n.includes(nm)) { best = z; bestLen = nm.length; }
  1301. return best;
  1302. }
  1303. const noDetect = () => new Set(store.get(PREFIX + 'nodetect', []));
  1304. let unlinkedDbs = [];
  1305. let detecting = false;
  1306. // Link storage written before tracking existed to games by name. Returns true if anything changed.
  1307. async function autoDetect() {
  1308. if (loadState_ !== 'ready') return false;
  1309. const skip = noDetect();
  1310. let changed = false;
  1311. for (const k of unassignedKeys()) {
  1312. if (skip.has(k)) continue;
  1313. const z = guessGame(k);
  1314. if (z) { attribute(String(z.id), [k], [], 'detected'); changed = true; }
  1315. }
  1316. const all = await dbNames();
  1317. const owned = new Set(Object.values(saves).flatMap(e => e.dbs || []));
  1318. const before = unlinkedDbs.join('|');
  1319. unlinkedDbs = all ? [...all].filter(d => !owned.has(d) && !isCacheDb(d)) : [];
  1320. for (const d of [...unlinkedDbs]) {
  1321. if (skip.has('db:' + d)) continue;
  1322. const z = guessGame(d);
  1323. if (z) { attribute(String(z.id), [], [d], 'detected'); unlinkedDbs = unlinkedDbs.filter(x => x !== d); changed = true; }
  1324. }
  1325. return changed || before !== unlinkedDbs.join('|');
  1326. }
  1327. function linkTo(id, keys = [], dbs = []) {
  1328. for (const [oid, e] of Object.entries(saves)) {
  1329. e.keys = (e.keys || []).filter(k => !keys.includes(k));
  1330. e.dbs = (e.dbs || []).filter(d => !dbs.includes(d));
  1331. if (!e.keys.length && !e.dbs.length) delete saves[oid];
  1332. }
  1333. const skip = noDetect();
  1334. keys.forEach(k => skip.delete(k));
  1335. dbs.forEach(d => skip.delete('db:' + d));
  1336. store.set(PREFIX + 'nodetect', [...skip]);
  1337. unlinkedDbs = unlinkedDbs.filter(d => !dbs.includes(d));
  1338. attribute(String(id), keys, dbs, 'manual');
  1339. }
  1340. function unlinkSave(id) {
  1341. const e = saves[id];
  1342. if (!e) return;
  1343. const skip = noDetect();
  1344. (e.keys || []).forEach(k => skip.add(k));
  1345. (e.dbs || []).forEach(d => skip.add('db:' + d));
  1346. store.set(PREFIX + 'nodetect', [...skip]);
  1347. unlinkedDbs.push(...(e.dbs || []).filter(d => !isCacheDb(d)));
  1348. delete saves[id];
  1349. saveSaves();
  1350. }
  1351. let unlinkedGroups = [];
  1352. function groupUnlinked() {
  1353. const groups = new Map();
  1354. const add = (label, kind, name) => {
  1355. if (!groups.has(label)) groups.set(label, { label, keys: [], dbs: [] });
  1356. groups.get(label)[kind].push(name);
  1357. };
  1358. unassignedKeys().forEach(k => add(k.split(/[:_.\/\-\s]/).filter(Boolean)[0] || k, 'keys', k));
  1359. const owned = new Set(Object.values(saves).flatMap(e => e.dbs || []));
  1360. unlinkedDbs.filter(d => !owned.has(d)).forEach(d => add(d, 'dbs', d));
  1361. return [...groups.values()];
  1362. }
  1363. function openGamePicker(title, onPick) {
  1364. const body = openPopup(title, `
  1365. <div class="search" style="max-width:none;margin-bottom:14px"><i class="ic" data-ic="search"></i><input class="pick-input" placeholder="Search games..." autocomplete="off" spellcheck="false" style="padding-right:14px"></div>
  1366. <div class="pick-list"></div>`, { wide: true });
  1367. const input = body.querySelector('input'), list = body.querySelector('.pick-list');
  1368. const draw = () => {
  1369. const q = input.value.trim().toLowerCase();
  1370. let pool = zones.filter(z => z.id >= 0 && !isExternal(z));
  1371. if (q) pool = pool.filter(z => z.name.toLowerCase().includes(q));
  1372. else pool = [...new Set([...recent.map(r => byId(r.id)).filter(z => z && !isExternal(z)), ...sortList(pool, 'popular')])];
  1373. list.innerHTML = pool.slice(0, 48).map(z => {
  1374. const r = recent.find(x => x.id === String(z.id));
  1375. return `<button class="pick" data-pick="${esc(z.id)}"><img src="${esc(fill(z.cover))}" alt="" loading="lazy"><span><b>${esc(z.name)}</b><small>${r ? 'played ' + ago(r.last) : '#' + esc(z.id)}</small></span></button>`;
  1376. }).join('') || '<p>No games match.</p>';
  1377. };
  1378. input.oninput = draw;
  1379. draw();
  1380. setTimeout(() => input.focus(), 50);
  1381. list.onclick = e => {
  1382. const b = e.target.closest('[data-pick]');
  1383. if (!b) return;
  1384. closePopup();
  1385. onPick(byId(b.dataset.pick));
  1386. };
  1387. }
  1388.  
  1389. function saveCardHTML(id, e, owners) {
  1390. const z = byId(id);
  1391. const r = recent.find(x => x.id === id);
  1392. const keys = e.keys || [], dbs = e.dbs || [];
  1393. const shared = keys.concat(dbs.map(d => 'db:' + d)).filter(k => (owners[k] || []).length > 1).length;
  1394. const [srcLabel, srcCls] = SRC[e.source] || SRC.tracked;
  1395. const tags = z && Array.isArray(z.special) ? z.special.slice(0, 2) : [];
  1396. const chips = keys.map(k => ({ k, db: false })).concat(dbs.map(d => ({ k: d, db: true })));
  1397. const sid = esc(id);
  1398. return `<article class="save-card">
  1399. <div class="sc-cover" ${z ? `data-open="${sid}" title="Play ${esc(z.name)}"` : ''}>
  1400. ${z ? `<img src="${esc(fill(z.cover))}" alt="" loading="lazy"><span class="sc-play"><i class="ic">${ic('play')}</i></span>` : `<i class="ic">${ic('database')}</i>`}
  1401. </div>
  1402. <div class="sc-main">
  1403. <div class="sc-top"><span class="src ${srcCls}">${srcLabel}</span><span class="sc-id">#${sid}</span></div>
  1404. <h3 class="sc-name" ${z ? `data-open="${sid}"` : ''}>${esc(z ? z.name : 'Unknown game #' + id)}</h3>
  1405. <div class="sc-by">${z && z.author ? `<span>by ${esc(z.author)}</span>` : ''}${tags.map(t => `<span class="tag">${esc(t)}</span>`).join('')}</div>
  1406. <dl class="sc-stats">
  1407. <div><dt>Save size</dt><dd>${keys.length ? fmtBytes(lsBytes(keys)) : '—'}${dbs.length ? ` + ${dbs.length} DB` : ''}</dd></div>
  1408. <div><dt>Last write</dt><dd>${e.updated ? ago(e.updated) : 'before tracking'}</dd></div>
  1409. <div><dt>Last played</dt><dd>${r ? ago(r.last) : '—'}</dd></div>
  1410. <div><dt>Playtime</dt><dd>${r ? fmtDur(r.total || 0) : '—'}</dd></div>
  1411. </dl>
  1412. <div class="sc-keys">${chips.slice(0, 3).map(c => `<code class="kchip${c.db ? ' db' : ''}" title="${esc(c.k)}">${c.db ? 'DB ' : ''}${esc(c.k)}</code>`).join('')}${chips.length > 3 ? `<span class="kmore">+${chips.length - 3} more</span>` : ''}</div>
  1413. ${shared ? `<div class="sc-warn"><i class="ic">${ic('alert')}</i>${shared} entr${shared === 1 ? 'y is' : 'ies are'} shared with another game</div>` : ''}
  1414. <div class="sc-actions">
  1415. ${z ? `<button class="btn sm primary" data-open="${sid}"><i class="ic">${ic('play')}</i>Play</button>` : ''}
  1416. <button class="btn sm" data-act="save-details" data-id="${sid}"><i class="ic">${ic('eye')}</i>Details</button>
  1417. <button class="btn sm icon" data-act="save-export" data-id="${sid}" title="Export this save">${ic('download')}</button>
  1418. <button class="btn sm icon" data-act="save-move" data-id="${sid}" title="Wrong game? Link it to a different one">${ic('link')}</button>
  1419. <button class="btn sm icon danger" data-act="save-delete" data-id="${sid}" title="Delete this save">${ic('trash')}</button>
  1420. </div>
  1421. </div>
  1422. </article>`;
  1423. }
  1424. function renderSaves() {
  1425. pruneSaves();
  1426. const entries = Object.entries(saves).sort((a, b) => (b[1].updated || 0) - (a[1].updated || 0));
  1427. unlinkedGroups = groupUnlinked();
  1428. let html = `
  1429. <div class="save-top">
  1430. <div class="panel">
  1431. <h3>Device storage</h3>
  1432. <p id="storeText">Measuring…</p>
  1433. <div class="meter"><i id="storeMeter"></i></div>
  1434. <div class="save-actions">
  1435. <button class="btn primary" data-act="export"><i class="ic">${ic('download')}</i>Export all data</button>
  1436. <button class="btn" data-act="import"><i class="ic">${ic('upload')}</i>Import data</button>
  1437. </div>
  1438. </div>
  1439. <div class="panel">
  1440. <h3>How saves are linked</h3>
  1441. <p>All games share this site's storage, so each save is tied to its game three ways:</p>
  1442. <div class="src-legend">
  1443. <div><span class="src ok">${SRC.tracked[0]}</span>the game wrote it while you played</div>
  1444. <div><span class="src auto">${SRC.detected[0]}</span>older data matched by the game's name</div>
  1445. <div><span class="src manual">${SRC.manual[0]}</span>you picked the game</div>
  1446. </div>
  1447. </div>
  1448. </div>`;
  1449. if (!entries.length && !unlinkedGroups.length) {
  1450. return html + emptyState('save', 'No save data yet', 'Play a game that saves progress and it will show up here with the game it belongs to, its size, and buttons to export or wipe it.', `<button class="btn primary" data-go="games">Browse games</button>`);
  1451. }
  1452. const owners = {};
  1453. entries.forEach(([id, e]) => (e.keys || []).concat((e.dbs || []).map(d => 'db:' + d)).forEach(k => (owners[k] = owners[k] || []).push(id)));
  1454. let n = 1;
  1455. const head = (title, count) => `<div class="section-head" style="margin-top:${n === 1 ? 0 : 34}px"><span class="section-idx">${String(n++).padStart(2, '0')}</span><h2>${title}</h2><span class="count">${count}</span><span class="rule"></span></div>`;
  1456. if (entries.length) html += head('Game saves', entries.length) + `<div class="save-grid">${entries.map(([id, e]) => saveCardHTML(id, e, owners)).join('')}</div>`;
  1457. if (unlinkedGroups.length) {
  1458. html += head('Unlinked data', unlinkedGroups.length) + `<p class="unl-note">Stored by a game, but we can't tell which one. If you know, link it and it moves up into Game saves.</p><div class="list">`;
  1459. unlinkedGroups.forEach((g, i) => {
  1460. const chips = g.keys.map(k => `<code class="kchip" title="${esc(k)}">${esc(k)}</code>`).concat(g.dbs.map(d => `<code class="kchip db" title="${esc(d)}">DB ${esc(d)}</code>`));
  1461. html += `<div class="row">
  1462. <div class="row-thumb unl-thumb"><i class="ic">${ic('database')}</i></div>
  1463. <div class="row-main">
  1464. <div class="row-title">${esc(g.label)}</div>
  1465. <div class="row-meta"><span>${[g.keys.length ? `${g.keys.length} key${g.keys.length === 1 ? '' : 's'} · ${fmtBytes(lsBytes(g.keys))}` : '', g.dbs.length ? `${g.dbs.length} database${g.dbs.length === 1 ? '' : 's'}` : ''].filter(Boolean).join(' · ')}</span></div>
  1466. <div class="sc-keys" style="margin-top:6px">${chips.slice(0, 4).join('')}${chips.length > 4 ? `<span class="kmore">+${chips.length - 4} more</span>` : ''}</div>
  1467. </div>
  1468. <div class="row-actions">
  1469. <button class="btn sm primary" data-act="link-group" data-i="${i}"><i class="ic">${ic('link')}</i>Link to game</button>
  1470. <button class="btn sm icon" data-act="group-details" data-i="${i}" title="Details">${ic('eye')}</button>
  1471. </div>
  1472. </div>`;
  1473. });
  1474. html += `</div>`;
  1475. }
  1476. return html;
  1477. }
  1478. async function fillSaveSizes() {
  1479. const el = document.getElementById('storeText'), m = document.getElementById('storeMeter');
  1480. if (!el) return;
  1481. try {
  1482. const est = await navigator.storage.estimate();
  1483. el.innerHTML = `<b style="color:var(--text)">${fmtBytes(est.usage)}</b> used of ${fmtBytes(est.quota)} available to this site · localStorage ${fmtBytes(lsBytes(allLsKeys()))}`;
  1484. m.style.width = Math.max(1, Math.min(100, est.usage / est.quota * 100)) + '%';
  1485. } catch (e) {
  1486. el.textContent = `localStorage ${fmtBytes(lsBytes(allLsKeys()))}`;
  1487. }
  1488. }
  1489. function allLsKeys() { const a = []; for (let i = 0; i < localStorage.length; i++) a.push(localStorage.key(i)); return a; }
  1490. async function updateStorageMeter() {
  1491. try {
  1492. const est = await navigator.storage.estimate();
  1493. document.getElementById('sideUsage').textContent = fmtBytes(est.usage);
  1494. document.getElementById('sideQuota').textContent = 'of ' + fmtBytes(est.quota);
  1495. document.getElementById('sideMeter').style.width = Math.max(1, Math.min(100, est.usage / est.quota * 100)) + '%';
  1496. } catch (e) {
  1497. document.getElementById('sideUsage').textContent = fmtBytes(lsBytes(allLsKeys()));
  1498. }
  1499. }
  1500.  
  1501. function keyTable(keys) {
  1502. return `<div class="ktable">${keys.map(k => {
  1503. const v = localStorage.getItem(k) || '';
  1504. return `<div class="krow"><div><code>${esc(k)}</code><small>${esc(v.length > 90 ? v.slice(0, 90) + '…' : v)}</small></div><span>${fmtBytes((k.length + v.length) * 2)}</span></div>`;
  1505. }).join('')}</div>`;
  1506. }
  1507. function showSaveDetails(id) {
  1508. id = String(id);
  1509. const e = saves[id];
  1510. if (!e) return;
  1511. const z = byId(id), r = recent.find(x => x.id === id);
  1512. const [srcLabel, srcCls] = SRC[e.source] || SRC.tracked;
  1513. const why = {
  1514. tracked: 'This game wrote this data while you were playing it here.',
  1515. manual: 'You linked this data to this game.',
  1516. detected: 'Matched to this game because the storage name contains the game\'s name. If that\'s wrong, use Change game.'
  1517. }[e.source || 'tracked'];
  1518. const sid = esc(id);
  1519. openPopup('Save data', `
  1520. <div class="sd-head">
  1521. ${z ? `<img src="${esc(fill(z.cover))}" alt="">` : `<div class="sd-ph"><i class="ic" data-ic="database"></i></div>`}
  1522. <div style="min-width:0"><span class="src ${srcCls}">${srcLabel}</span><h2>${esc(z ? z.name : 'Unknown game #' + id)}</h2>
  1523. <p>${z && z.author ? 'by ' + esc(z.author) + ' · ' : ''}#${sid}${z && z.special ? ' · ' + esc([].concat(z.special).join(', ')) : ''}</p></div>
  1524. </div>
  1525. <p class="sd-src">${why}</p>
  1526. <dl class="kv">
  1527. <dt>Save size</dt><dd>${fmtBytes(lsBytes(e.keys || []))}${(e.dbs || []).length ? ` + ${e.dbs.length} database${e.dbs.length === 1 ? '' : 's'}` : ''}</dd>
  1528. <dt>Last write</dt><dd>${e.updated ? new Date(e.updated).toLocaleString() : 'Before tracking started'}</dd>
  1529. <dt>First seen</dt><dd>${e.first ? new Date(e.first).toLocaleString() : '—'}</dd>
  1530. <dt>Last played</dt><dd>${r ? new Date(r.last).toLocaleString() : 'Not played here yet'}</dd>
  1531. <dt>Playtime</dt><dd>${r ? `${fmtDur(r.total || 0)} over ${r.sessions || 1} session${(r.sessions || 1) === 1 ? '' : 's'}` : '—'}</dd>
  1532. </dl>
  1533. <h3>Storage keys (${(e.keys || []).length})</h3>
  1534. ${(e.keys || []).length ? keyTable(e.keys) : '<p>none</p>'}
  1535. ${(e.dbs || []).length ? `<h3>IndexedDB databases (${e.dbs.length})</h3><div class="sc-keys">${e.dbs.map(d => `<code class="kchip db">${esc(d)}</code>`).join('')}</div>` : ''}
  1536. <div class="btn-row">
  1537. ${z ? `<button class="btn sm primary" data-open="${sid}"><i class="ic" data-ic="play"></i>Play</button>` : ''}
  1538. <button class="btn sm" data-act="save-export" data-id="${sid}"><i class="ic" data-ic="download"></i>Export</button>
  1539. <button class="btn sm" data-act="save-move" data-id="${sid}"><i class="ic" data-ic="link"></i>Change game</button>
  1540. <button class="btn sm" data-act="save-unlink" data-id="${sid}"><i class="ic" data-ic="x"></i>Unlink</button>
  1541. <button class="btn sm danger" data-act="save-delete" data-id="${sid}"><i class="ic" data-ic="trash"></i>Delete</button>
  1542. </div>`, { wide: true });
  1543. }
  1544. function showGroupDetails(i) {
  1545. const g = unlinkedGroups[i];
  1546. if (!g) return;
  1547. openPopup('Unlinked data', `
  1548. <p style="margin-top:0">This data is in the site's storage but isn't linked to any game yet. The values below can hint at which game wrote it.</p>
  1549. <h3>Storage keys (${g.keys.length})</h3>
  1550. ${g.keys.length ? keyTable(g.keys) : '<p>none</p>'}
  1551. ${g.dbs.length ? `<h3>IndexedDB databases (${g.dbs.length})</h3><div class="sc-keys">${g.dbs.map(d => `<code class="kchip db">${esc(d)}</code>`).join('')}</div>` : ''}
  1552. <div class="btn-row">
  1553. <button class="btn sm primary" data-act="link-group" data-i="${i}"><i class="ic" data-ic="link"></i>Link to a game</button>
  1554. <button class="btn sm danger" data-act="group-delete" data-i="${i}"><i class="ic" data-ic="trash"></i>Delete</button>
  1555. </div>`, { wide: true });
  1556. }
  1557. function updateHudSave(flash) {
  1558. const b = document.getElementById('hudSave');
  1559. const e = currentZone && saves[String(currentZone.id)];
  1560. b.classList.toggle('hidden', !e);
  1561. if (!e) return;
  1562. document.getElementById('hudSaveText').textContent = e.updated ? `SAVED ${ago(e.updated).toUpperCase()}` : 'HAS SAVE';
  1563. b.title = `${currentZone.name} save data: ${fmtBytes(lsBytes(e.keys || []))}${(e.dbs || []).length ? ` + ${e.dbs.length} DB` : ''}`;
  1564. if (flash) { b.classList.remove('flash'); void b.offsetWidth; b.classList.add('flash'); }
  1565. }
  1566.  
  1567. async function exportGameSave(id) {
  1568. const e = saves[id];
  1569. if (!e) return;
  1570. const z = byId(id);
  1571. const t = toast('Packing save…');
  1572. const result = { cookies: '', localStorage: {}, sessionStorage: {}, indexedDB: {}, caches: {} };
  1573. (e.keys || []).forEach(k => { const v = localStorage.getItem(k); if (v != null) result.localStorage[k] = v; });
  1574. try { result.indexedDB = await dumpIndexedDB(e.dbs || []); } catch (err) {}
  1575. downloadBlob(JSON.stringify(result), `${(z ? z.name : 'game-' + id).replace(/[^\w\- ]+/g, '').trim() || 'save'}-save.data`);
  1576. t.remove();
  1577. toast('Save exported. Import it with Import data.', 'ok');
  1578. }
  1579.  
  1580. async function deleteGameSave(id) {
  1581. const e = saves[id];
  1582. if (!e) return;
  1583. const z = byId(id);
  1584. const others = new Set();
  1585. Object.entries(saves).forEach(([oid, oe]) => { if (oid !== id && ((oe.keys || []).some(k => e.keys.includes(k)) || (oe.dbs || []).some(d => (e.dbs || []).includes(d)))) others.add(byId(oid)?.name || '#' + oid); });
  1586. const ok = await askConfirm('Delete save?', `
  1587. <p style="margin-top:0">This wipes <b>${(e.keys || []).length}</b> storage key(s)${(e.dbs || []).length ? ` and <b>${e.dbs.length}</b> database(s)` : ''} for <b>${esc(z ? z.name : '#' + id)}</b>. Progress in that game will be lost.</p>
  1588. ${others.size ? `<p style="color:var(--warn)">Some of this data is shared with: ${[...others].map(esc).join(', ')}. Their progress may reset too.</p>` : ''}
  1589. <p>Tip: export it first if you might want it back.</p>`, 'Delete save', true);
  1590. if (!ok) return;
  1591. (e.keys || []).forEach(k => { try { localStorage.removeItem(k); } catch (err) {} });
  1592. for (const db of e.dbs || []) { try { indexedDB.deleteDatabase(db); } catch (err) {} }
  1593. delete saves[id];
  1594. Object.values(saves).forEach(oe => { oe.keys = (oe.keys || []).filter(k => !e.keys.includes(k)); oe.dbs = (oe.dbs || []).filter(d => !(e.dbs || []).includes(d)); });
  1595. saveSaves();
  1596. render();
  1597. toast('Save deleted.', 'ok');
  1598. }
  1599.  
  1600. /* ================= tracking (recent + saves) ================= */
  1601. let track = null; // { id, snap: Map, dbs: Set, start, lastTick }
  1602. function snapshotLS() {
  1603. const snap = new Map();
  1604. for (let i = 0; i < localStorage.length; i++) {
  1605. const k = localStorage.key(i);
  1606. if (k && !k.startsWith(PREFIX)) snap.set(k, localStorage.getItem(k));
  1607. }
  1608. return snap;
  1609. }
  1610. async function dbNames() {
  1611. try { return new Set((await indexedDB.databases()).map(d => d.name).filter(Boolean)); } catch (e) { return null; }
  1612. }
  1613. function touchRecent(id) {
  1614. id = String(id);
  1615. let r = recent.find(x => x.id === id);
  1616. if (r) recent = recent.filter(x => x !== r);
  1617. else r = { id, total: 0, sessions: 0 };
  1618. r.last = Date.now();
  1619. r.sessions = (r.sessions || 0) + 1;
  1620. recent.unshift(r);
  1621. recent = recent.slice(0, 200);
  1622. saveRecent();
  1623. }
  1624. function attribute(id, keys = [], dbs = [], source = 'tracked', bump = source === 'tracked') {
  1625. if (!keys.length && !dbs.length) return;
  1626. const e = saves[id] || (saves[id] = { keys: [], dbs: [], first: Date.now(), updated: 0, source });
  1627. keys.forEach(k => { if (!e.keys.includes(k)) e.keys.push(k); });
  1628. dbs.forEach(d => { if (!e.dbs.includes(d)) e.dbs.push(d); });
  1629. if ((SRC_RANK[source] ?? 2) > (SRC_RANK[e.source || 'tracked'] ?? 2)) e.source = source;
  1630. if (bump) e.updated = Date.now();
  1631. saveSaves();
  1632. if (currentZone && String(currentZone.id) === String(id)) updateHudSave(bump);
  1633. }
  1634. function hookFrame(win, id) {
  1635. // games run same-origin in the iframe, so we can see which IndexedDB databases they write to
  1636. try {
  1637. let lastWrite = 0;
  1638. for (const m of ['put', 'add', 'delete', 'clear']) {
  1639. const orig = win.IDBObjectStore.prototype[m];
  1640. win.IDBObjectStore.prototype[m] = function (...args) {
  1641. try {
  1642. const name = this.transaction.db.name, now = Date.now();
  1643. if (!isCacheDb(name) && now - lastWrite > 3000) { lastWrite = now; attribute(id, [], [name]); }
  1644. } catch (e) {}
  1645. return orig.apply(this, args);
  1646. };
  1647. }
  1648. } catch (e) {}
  1649. }
  1650. function beginTracking(id) {
  1651. track = { id: String(id), snap: snapshotLS(), dbs: null, start: Date.now(), lastTick: Date.now(), visible: !document.hidden };
  1652. dbNames().then(s => { if (track && track.id === String(id)) track.dbs = s; });
  1653. }
  1654. function scanTracking() {
  1655. if (!track) return;
  1656. const changed = [];
  1657. for (let i = 0; i < localStorage.length; i++) {
  1658. const k = localStorage.key(i);
  1659. if (!k || k.startsWith(PREFIX)) continue;
  1660. const v = localStorage.getItem(k);
  1661. if (!track.snap.has(k) || track.snap.get(k) !== v) { changed.push(k); track.snap.set(k, v); }
  1662. }
  1663. attribute(track.id, changed);
  1664. if (track.dbs) {
  1665. const t = track;
  1666. dbNames().then(now => {
  1667. if (!now || !t.dbs) return;
  1668. const fresh = [...now].filter(n => !t.dbs.has(n) && !isCacheDb(n));
  1669. fresh.forEach(n => t.dbs.add(n));
  1670. attribute(t.id, [], fresh);
  1671. });
  1672. }
  1673. }
  1674. function tickPlaytime() {
  1675. if (!track) return;
  1676. // only count the stretch since the last tick if the tab was visible during it
  1677. const now = Date.now();
  1678. if (track.visible) {
  1679. const r = recent.find(x => x.id === track.id);
  1680. if (r) r.total = (r.total || 0) + (now - track.lastTick);
  1681. }
  1682. track.lastTick = now;
  1683. track.visible = !document.hidden;
  1684. saveRecent();
  1685. }
  1686. function flushTracking() {
  1687. if (!track) return;
  1688. try { scanTracking(); tickPlaytime(); } catch (e) {}
  1689. }
  1690. let tickN = 0;
  1691. setInterval(() => {
  1692. if (!track) return;
  1693. document.getElementById('hudTimer').textContent = fmtClock(Date.now() - track.start);
  1694. if (++tickN % 4 === 0) { scanTracking(); tickPlaytime(); updateHudSave(); }
  1695. }, 1000);
  1696.  
  1697. /* ================= zone viewer ================= */
  1698. function openZone(file) {
  1699. if (!file) return;
  1700. if (isExternal(file)) {
  1701. touchRecent(file.id);
  1702. updateNav();
  1703. window.open(file.url, "_blank");
  1704. return;
  1705. }
  1706. if (track) closeZone(true);
  1707. currentZone = file;
  1708. document.getElementById('zoneName').textContent = file.name;
  1709. document.getElementById('zoneId').textContent = file.id;
  1710. const author = document.getElementById('zoneAuthor');
  1711. author.textContent = file.author ? "by " + file.author : '';
  1712. author.href = file.authorLink || 'javascript:void(0)';
  1713. author.style.pointerEvents = file.authorLink ? '' : 'none';
  1714. document.getElementById('loaderName').textContent = file.name;
  1715. document.getElementById('hudTimer').textContent = '00:00';
  1716. syncHudFav();
  1717. updateHudSave();
  1718. loader.classList.remove('hidden');
  1719. zoneViewer.classList.add('open');
  1720. document.body.style.overflow = 'hidden';
  1721. const url = fill(file.url);
  1722. fetch(url + "?t=" + Date.now()).then(response => response.text()).then(html => {
  1723. if (currentZone !== file) return;
  1724. if (zoneFrame) zoneFrame.remove();
  1725. zoneFrame = document.createElement("iframe");
  1726. zoneFrame.id = "zoneFrame";
  1727. zoneFrame.setAttribute('allow', 'fullscreen; autoplay; gamepad; clipboard-write; pointer-lock');
  1728. zoneFrame.allowFullscreen = true;
  1729. stage.appendChild(zoneFrame);
  1730. touchRecent(file.id);
  1731. beginTracking(file.id);
  1732. const doc = zoneFrame.contentDocument;
  1733. doc.open();
  1734. hookFrame(zoneFrame.contentWindow, String(file.id));
  1735. doc.write(html);
  1736. doc.close();
  1737. loader.classList.add('hidden');
  1738. try { zoneFrame.contentWindow.focus(); } catch (e) {}
  1739. try {
  1740. const u = new URL(window.location);
  1741. u.searchParams.set('id', file.id);
  1742. history.pushState(null, '', u.toString());
  1743. } catch (error) {}
  1744. }).catch(error => {
  1745. toast("Failed to load game: " + error, 'err');
  1746. closeZone();
  1747. });
  1748. }
  1749.  
  1750. function closeZone(silent) {
  1751. flushTracking();
  1752. track = null;
  1753. currentZone = null;
  1754. if (document.fullscreenElement) { try { document.exitFullscreen(); } catch (e) {} }
  1755. if (zoneFrame) { zoneFrame.remove(); zoneFrame = null; }
  1756. zoneViewer.classList.remove('open');
  1757. document.body.style.overflow = '';
  1758. try {
  1759. const url = new URL(window.location);
  1760. url.searchParams.delete('id');
  1761. history.pushState(null, '', url.toString());
  1762. } catch (error) {}
  1763. if (!silent) render();
  1764. }
  1765.  
  1766. function currentZoneObj() {
  1767. return zones.find(zone => zone.id + '' === document.getElementById('zoneId').textContent);
  1768. }
  1769. function aboutBlank() {
  1770. const newWindow = window.open("about:blank", "_blank");
  1771. const zone = fill(currentZoneObj().url);
  1772. fetch(zone + "?t=" + Date.now()).then(response => response.text()).then(html => {
  1773. if (newWindow) {
  1774. newWindow.document.open();
  1775. newWindow.document.write(html);
  1776. newWindow.document.close();
  1777. }
  1778. });
  1779. }
  1780. function downloadZone() {
  1781. const zone = currentZoneObj();
  1782. fetch(fill(zone.url) + "?t=" + Date.now()).then(res => res.text()).then(text => {
  1783. downloadBlob(text, zone.name + ".html", "text/plain;charset=utf-8");
  1784. }).catch(err => toast('Download failed: ' + err, 'err'));
  1785. }
  1786. function fullscreenZone() {
  1787. const el = zoneFrame || stage;
  1788. (el.requestFullscreen || el.webkitRequestFullscreen || el.mozRequestFullScreen || el.msRequestFullscreen)?.call(el);
  1789. }
  1790. function syncHudFav() {
  1791. const b = document.getElementById('hudFav');
  1792. const on = currentZone && favs.includes(String(currentZone.id));
  1793. b.classList.toggle('fav-on', !!on);
  1794. b.title = on ? 'Remove from favorites' : 'Add to favorites';
  1795. }
  1796. function toggleFav(id) {
  1797. id = String(id);
  1798. const on = favs.includes(id);
  1799. favs = on ? favs.filter(x => x !== id) : [id, ...favs];
  1800. saveFavs();
  1801. document.querySelectorAll(`[data-fav="${CSS.escape(id)}"]`).forEach(b => {
  1802. b.classList.toggle('on', !on);
  1803. if (!b.classList.contains('fav')) b.style.color = on ? '' : 'var(--warn)';
  1804. });
  1805. syncHudFav();
  1806. updateNav();
  1807. if (ui.view === 'library' && ui.sub === 'favorites' && !zoneViewer.classList.contains('open')) render();
  1808. toast(on ? 'Removed from favorites' : `Added to favorites`, on ? '' : 'ok', { ms: 1800 });
  1809. }
  1810. function playRandom() {
  1811. const pool = zones.filter(z => z.id >= 0 && !isExternal(z));
  1812. if (pool.length) openZone(pool[Math.floor(Math.random() * pool.length)]);
  1813. }
  1814.  
  1815. /* ================= data export / import ================= */
  1816. function sanitizeData(obj, maxStringLen = 1000, maxArrayLen = 10000) {
  1817. if (typeof obj === 'string') return obj.length > maxStringLen ? obj.slice(0, maxStringLen) + '...[truncated]' : obj;
  1818. if (obj instanceof Uint8Array) return obj.length > maxArrayLen ? `[Uint8Array too large (${obj.length} bytes), truncated]` : obj;
  1819. if (Array.isArray(obj)) return obj.map(item => sanitizeData(item, maxStringLen, maxArrayLen));
  1820. if (obj && typeof obj === 'object') {
  1821. const newObj = {};
  1822. for (const key in obj) if (obj.hasOwnProperty(key)) newObj[key] = sanitizeData(obj[key], maxStringLen, maxArrayLen);
  1823. return newObj;
  1824. }
  1825. return obj;
  1826. }
  1827. function toBase64(buffer) {
  1828. const bytes = new Uint8Array(buffer);
  1829. let bin = '';
  1830. for (let i = 0; i < bytes.length; i += 0x8000) bin += String.fromCharCode.apply(null, bytes.subarray(i, i + 0x8000));
  1831. return btoa(bin);
  1832. }
  1833. function downloadBlob(text, name, type = "application/octet-stream") {
  1834. const link = document.createElement("a");
  1835. link.href = URL.createObjectURL(new Blob([text], { type }));
  1836. link.download = name;
  1837. document.body.appendChild(link);
  1838. link.click();
  1839. document.body.removeChild(link);
  1840. setTimeout(() => URL.revokeObjectURL(link.href), 4000);
  1841. }
  1842. async function dumpIndexedDB(onlyNames) {
  1843. const out = {};
  1844. let dbs = await indexedDB.databases();
  1845. if (onlyNames) dbs = dbs.filter(d => onlyNames.includes(d.name));
  1846. for (const dbInfo of dbs) {
  1847. if (!dbInfo.name) continue;
  1848. out[dbInfo.name] = {};
  1849. await new Promise((resolve, reject) => {
  1850. const openRequest = indexedDB.open(dbInfo.name, dbInfo.version);
  1851. openRequest.onerror = () => reject(openRequest.error);
  1852. openRequest.onsuccess = () => {
  1853. const db = openRequest.result;
  1854. const storeNames = Array.from(db.objectStoreNames);
  1855. if (storeNames.length === 0) { db.close(); resolve(); return; }
  1856. const transaction = db.transaction(storeNames, "readonly");
  1857. const storePromises = storeNames.map(storeName => new Promise((res, rej) => {
  1858. out[dbInfo.name][storeName] = [];
  1859. const getAllRequest = transaction.objectStore(storeName).getAll();
  1860. getAllRequest.onsuccess = () => { out[dbInfo.name][storeName] = sanitizeData(getAllRequest.result, 1000, 100); res(); };
  1861. getAllRequest.onerror = () => rej(getAllRequest.error);
  1862. }));
  1863. Promise.all(storePromises).then(() => { db.close(); resolve(); }, reject);
  1864. };
  1865. });
  1866. }
  1867. return out;
  1868. }
  1869. async function saveData() {
  1870. flushTracking();
  1871. const t = toast('Exporting everything… keep this tab open', '', { ms: 60000 });
  1872. try {
  1873. const result = {};
  1874. result.cookies = document.cookie;
  1875. result.localStorage = { ...localStorage };
  1876. result.sessionStorage = { ...sessionStorage };
  1877. result.indexedDB = await dumpIndexedDB();
  1878. result.caches = {};
  1879. const cacheNames = await caches.keys();
  1880. for (const cacheName of cacheNames) {
  1881. const cache = await caches.open(cacheName);
  1882. const requests = await cache.keys();
  1883. result.caches[cacheName] = [];
  1884. for (const req of requests) {
  1885. const response = await cache.match(req);
  1886. if (!response) continue;
  1887. const cloned = response.clone();
  1888. const contentType = cloned.headers.get('content-type') || '';
  1889. let body;
  1890. try {
  1891. if (contentType.includes('application/json')) body = await cloned.json();
  1892. else if (contentType.includes('text') || contentType.includes('javascript')) body = await cloned.text();
  1893. else body = toBase64(await cloned.arrayBuffer());
  1894. } catch (e) {
  1895. body = '[Unable to read body]';
  1896. }
  1897. result.caches[cacheName].push({ url: req.url, body, contentType });
  1898. }
  1899. }
  1900. downloadBlob(JSON.stringify(result), `${Date.now()}.data`);
  1901. t.remove();
  1902. toast('Export done, check your downloads.', 'ok');
  1903. } catch (err) {
  1904. t.remove();
  1905. toast('Export failed: ' + err, 'err');
  1906. }
  1907. }
  1908. async function loadData(event) {
  1909. const file = event.target.files[0];
  1910. if (!file) return;
  1911. const t = toast('Importing… keep this tab open', '', { ms: 60000 });
  1912. const reader = new FileReader();
  1913. reader.onload = async function (e) {
  1914. try {
  1915. const data = JSON.parse(e.target.result);
  1916. if (data.cookies) data.cookies.split(';').forEach(cookie => { if (cookie.trim()) document.cookie = cookie.trim(); });
  1917. if (data.localStorage) for (const key in data.localStorage) localStorage.setItem(key, data.localStorage[key]);
  1918. if (data.sessionStorage) for (const key in data.sessionStorage) sessionStorage.setItem(key, data.sessionStorage[key]);
  1919. if (data.indexedDB) {
  1920. for (const dbName in data.indexedDB) {
  1921. const stores = data.indexedDB[dbName];
  1922. if (!Object.keys(stores).length) continue;
  1923. await new Promise((resolve, reject) => {
  1924. const request = indexedDB.open(dbName, 1);
  1925. request.onupgradeneeded = e => {
  1926. const db = e.target.result;
  1927. for (const storeName in stores) {
  1928. if (!db.objectStoreNames.contains(storeName)) db.createObjectStore(storeName, { keyPath: 'id', autoIncrement: true });
  1929. }
  1930. };
  1931. request.onsuccess = e => {
  1932. const db = e.target.result;
  1933. const transaction = db.transaction(Object.keys(stores), 'readwrite');
  1934. transaction.onerror = () => reject(transaction.error);
  1935. let pendingStores = Object.keys(stores).length;
  1936. for (const storeName in stores) {
  1937. const objectStore = transaction.objectStore(storeName);
  1938. objectStore.clear().onsuccess = () => {
  1939. for (const item of stores[storeName]) objectStore.put(item);
  1940. pendingStores--;
  1941. if (pendingStores === 0) resolve();
  1942. };
  1943. }
  1944. };
  1945. request.onerror = () => reject(request.error);
  1946. });
  1947. }
  1948. }
  1949. if (data.caches) {
  1950. for (const cacheName in data.caches) {
  1951. const cache = await caches.open(cacheName);
  1952. await cache.keys().then(keys => Promise.all(keys.map(k => cache.delete(k)))); // clear existing
  1953. for (const entry of data.caches[cacheName]) {
  1954. let responseBody;
  1955. if (entry.contentType.includes('application/json')) responseBody = JSON.stringify(entry.body);
  1956. else if (entry.contentType.includes('text') || entry.contentType.includes('javascript')) responseBody = entry.body;
  1957. else {
  1958. const binaryStr = atob(entry.body);
  1959. const bytes = new Uint8Array(binaryStr.length);
  1960. for (let i = 0; i < binaryStr.length; i++) bytes[i] = binaryStr.charCodeAt(i);
  1961. responseBody = bytes.buffer;
  1962. }
  1963. await cache.put(entry.url, new Response(responseBody, { headers: new Headers({ 'content-type': entry.contentType }) }));
  1964. }
  1965. }
  1966. }
  1967. loadState();
  1968. applySettings();
  1969. render();
  1970. t.remove();
  1971. toast('Data loaded.', 'ok');
  1972. } catch (err) {
  1973. t.remove();
  1974. toast('Import failed: ' + err, 'err');
  1975. }
  1976. event.target.value = '';
  1977. };
  1978. reader.readAsText(file);
  1979. }
  1980.  
  1981. /* ================= popups ================= */
  1982. function openPopup(title, html, opts = {}) {
  1983. document.getElementById('popupTitle').textContent = title;
  1984. const body = document.getElementById('popupBody');
  1985. body.innerHTML = html;
  1986. hydrateIcons(body);
  1987. document.getElementById('popup').classList.toggle('wide', !!opts.wide);
  1988. document.getElementById('popupOverlay').classList.add('open');
  1989. return body;
  1990. }
  1991. function closePopup() {
  1992. document.getElementById('popupOverlay').classList.remove('open');
  1993. if (confirmResolve) { confirmResolve(false); confirmResolve = null; }
  1994. }
  1995. let confirmResolve = null;
  1996. function askConfirm(title, html, okLabel = 'Confirm', danger = false) {
  1997. return new Promise(resolve => {
  1998. const body = openPopup(title, html + `<div class="btn-row end"><button class="btn" data-confirm="0">Cancel</button><button class="btn ${danger ? 'danger' : 'primary'}" data-confirm="1">${esc(okLabel)}</button></div>`);
  1999. confirmResolve = resolve;
  2000. body.querySelectorAll('[data-confirm]').forEach(b => b.onclick = () => {
  2001. const r = confirmResolve; confirmResolve = null;
  2002. closePopup();
  2003. r && r(b.dataset.confirm === '1');
  2004. });
  2005. });
  2006. }
  2007.  
  2008. function cloakIcon(url) {
  2009. const link = document.querySelector("link[rel~='icon']");
  2010. link.rel = "icon";
  2011. link.href = (url + "").trim().length === 0 ? "favicon.png" : url;
  2012. document.head.appendChild(link);
  2013. }
  2014. function cloakName(string) {
  2015. document.title = (string + "").trim().length === 0 ? "gn-math" : string;
  2016. }
  2017.  
  2018. function openSettings() {
  2019. const accents = [['blue', '#00d4ff', '#2f6bff', 'Neon Blue'], ['ice', '#7af7ff', '#00a3ff', 'Ice'], ['synth', '#ff3df2', '#7b2bff', 'Synthwave'], ['toxic', '#3dff8f', '#00b3a1', 'Toxic'], ['solar', '#ffb020', '#ff4d2b', 'Solar']];
  2020. const sw = (k, v) => `<button class="switch${settings[k] ? ' on' : ''}" data-setting="${k}" role="switch" aria-checked="${!!settings[k]}" aria-label="${v}"></button>`;
  2021. const body = openPopup('Settings', `
  2022. <div class="field"><span class="lbl">Accent</span>
  2023. <div class="swatches">${accents.map(([k, a, b, l]) => `<button class="swatch${settings.accent === k ? ' on' : ''}" data-accent="${k}" title="${l}"><i style="background:linear-gradient(135deg,${a},${b})"></i></button>`).join('')}</div>
  2024. </div>
  2025. <div class="field"><span class="lbl">Card size</span>
  2026. <div class="seg" style="width:auto">${[['s', 'Small'], ['m', 'Medium'], ['l', 'Large']].map(([k, l]) => `<button class="${settings.size === k ? 'on' : ''}" data-size="${k}">${l}</button>`).join('')}</div>
  2027. </div>
  2028. <div class="field">
  2029. <div class="toggle-row"><div><b>Scanlines</b><span>CRT line overlay across the screen</span></div>${sw('scan', 'Scanlines')}</div>
  2030. <div class="toggle-row"><div><b>Background motion</b><span>Moving grid floor and glitch effects</span></div>${sw('motion', 'Background motion')}</div>
  2031. <div class="toggle-row"><div><b>Confirm before leaving</b><span>Ask before the tab closes so a game is not lost mid-run</span></div>${sw('confirmLeave', 'Confirm before leaving')}</div>
  2032. </div>
  2033. <div class="field"><span class="lbl">Tab cloak</span>
  2034. <input class="input" id="tab-cloak-title" placeholder="Tab title…" value="${esc(settings.cloakTitle)}" style="margin-bottom:10px">
  2035. <input class="input" id="tab-cloak-icon" placeholder="Tab icon URL…" value="${esc(settings.cloakIcon)}">
  2036. <div class="btn-row"><button class="btn sm" data-act="cloak-reset">Reset tab</button></div>
  2037. </div>
  2038. <div class="field" style="margin-bottom:0"><span class="lbl">Data</span>
  2039. <div class="btn-row" style="margin-top:0">
  2040. <button class="btn sm" data-act="export"><i class="ic" data-ic="download"></i>Export data</button>
  2041. <button class="btn sm" data-act="import"><i class="ic" data-ic="upload"></i>Import data</button>
  2042. <button class="btn sm danger" data-act="clear-recent"><i class="ic" data-ic="trash"></i>Clear history</button>
  2043. </div>
  2044. </div>`);
  2045. body.querySelectorAll('[data-accent]').forEach(b => b.onclick = () => {
  2046. settings.accent = b.dataset.accent; saveSettings(); applySettings();
  2047. body.querySelectorAll('[data-accent]').forEach(x => x.classList.toggle('on', x === b));
  2048. });
  2049. body.querySelectorAll('[data-size]').forEach(b => b.onclick = () => {
  2050. settings.size = b.dataset.size; saveSettings(); applySettings();
  2051. body.querySelectorAll('[data-size]').forEach(x => x.classList.toggle('on', x === b));
  2052. });
  2053. body.querySelectorAll('[data-setting]').forEach(b => b.onclick = () => {
  2054. const k = b.dataset.setting; settings[k] = !settings[k]; saveSettings(); applySettings();
  2055. b.classList.toggle('on', settings[k]); b.setAttribute('aria-checked', settings[k]);
  2056. });
  2057. body.querySelector('#tab-cloak-title').oninput = e => { settings.cloakTitle = e.target.value; saveSettings(); cloakName(e.target.value); };
  2058. body.querySelector('#tab-cloak-icon').oninput = e => { settings.cloakIcon = e.target.value; saveSettings(); cloakIcon(e.target.value); };
  2059. }
  2060. function tabCloak() { openSettings(); setTimeout(() => document.getElementById('tab-cloak-title')?.focus(), 50); }
  2061.  
  2062. function showContact() {
  2063. openPopup('Contact', `
  2064. <dl class="kv"><dt>Discord</dt><dd><a href="https://discord.gg/NAFw4ykZ7n"; target="_blank" rel="noopener">https://discord.gg/NAFw4ykZ7n</a></dd>;
  2065. <dt>Email</dt><dd><a href="mailto:[email protected]">[email protected]</a></dd></dl>`);
  2066. }
  2067. function loadPrivacy() {
  2068. openPopup('Privacy Policy', `
  2069. <h2 style="margin-top:0">PRIVACY POLICY</h2>
  2070. <p>Last updated Feburary 20, 2026</p>
  2071. <p>This Privacy Notice for gn-math ("we," "us," or "our"), describes how and why we might access, collect, store, use, and/or share ("process") your personal information when you use our services ("Services"), including when you:</p>
  2072. <ul>
  2073. <li>Visit our website at <a href="https://gn-math.dev">https://gn-math.dev</a>;, or any website of ours that links to this Privacy Notice</li>
  2074. <li>Engage with us in other related ways, including any sales, marketing, or events</li>
  2075. </ul>
  2076. <p>Questions or concerns? Reading this Privacy Notice will help you understand your privacy rights and choices. We are responsible for making decisions about how your personal information is processed. If you do not agree with our policies and practices, please do not use our Services. If you still have any questions or concerns, please contact us at <a href="https://discord.gg/NAFw4ykZ7n">https://discord.gg/NAFw4ykZ7n</a>.</p>;
  2077. <h3>SUMMARY OF KEY POINTS</h3>
  2078. <p>This summary provides key points from our Privacy Notice, but you can find out more details about any of these topics by clicking the link following each key point or by using our table of contents below to find the section you are looking for.</p>
  2079. <p><strong>What personal information do we process?</strong> When you visit, use, or navigate our Services, we may process personal information depending on how you interact with us and the Services, the choices you make, and the products and features you use. Learn more about personal information you disclose to us.</p>
  2080. <p><strong>Do we process any sensitive personal information?</strong> Some of the information may be considered "special" or "sensitive" in certain jurisdictions, for example your racial or ethnic origins, sexual orientation, and religious beliefs. We do not process sensitive personal information.</p>
  2081. <p><strong>Do we collect any information from third parties?</strong> We do not collect any information from third parties.</p>
  2082. <p><strong>How do we process your information?</strong> We process your information to provide, improve, and administer our Services, communicate with you, for security and fraud prevention, and to comply with law. We may also process your information for other purposes with your consent. We process your information only when we have a valid legal reason to do so. Learn more about how we process your information.</p>
  2083. <p><strong>In what situations and with which parties do we share personal information?</strong> We may share information in specific situations and with specific third parties. Learn more about when and with whom we share your personal information.</p>
  2084. <p><strong>How do we keep your information safe?</strong> We have adequate organizational and technical processes and procedures in place to protect your personal information. However, no electronic transmission over the internet or information storage technology can be guaranteed to be 100% secure, so we cannot promise or guarantee that hackers, cybercriminals, or other unauthorized third parties will not be able to defeat our security and improperly collect, access, steal, or modify your information. Learn more about how we keep your information safe.</p>
  2085. <p><strong>What are your rights?</strong> Depending on where you are located geographically, the applicable privacy law may mean you have certain rights regarding your personal information. Learn more about your privacy rights.</p>
  2086. <p><strong>How do you exercise your rights?</strong> The easiest way to exercise your rights is by submitting a data subject access request, or by contacting us. We will consider and act upon any request in accordance with applicable data protection laws.</p>
  2087. `, { wide: true });
  2088. }
  2089. function loadDMCA() {
  2090. openPopup('DMCA', `
  2091. <p style="margin-top:0">If you own or developed a game that is on <strong>gn-math</strong> and would like it removed, please do one of the following:</p>
  2092. <ol>
  2093. <li><a href="https://discord.gg/D4c9VFYWyU"; target="_blank" rel="noopener noreferrer">Join the Discord</a> and DM <strong>breadbb</strong> or ping me in a public channel <strong>[INSTANT RESPONSE]</strong></li>
  2094. <li>Email me at <a href="mailto:[email protected]">[email protected]</a> with the subject starting with <code>!DMCA</code>. <strong>[DELAYED RESPONSE]</strong></li>
  2095. </ol>
  2096. <p>If you are going to do an email, please show proof you own the game before I have to ask.</p>`);
  2097. }
  2098.  
  2099. let _allStatsCache = null;
  2100. async function getAllStats() {
  2101. if (_allStatsCache) return _allStatsCache;
  2102. const PERIOD = "year";
  2103. const PAGE_BATCH = 5;
  2104. let page = 1;
  2105. let done = false;
  2106. const combinedMap = Object.create(null);
  2107. while (!done) {
  2108. const pages = Array.from({ length: PAGE_BATCH }, (_, i) => page + i);
  2109. const responses = await Promise.all(pages.map(p => fetch(`${BASE_URL}?period=${PERIOD}&page=${p}&limit=100`).then(r => (r.ok ? r.json() : [])).catch(() => [])));
  2110. for (const data of responses) {
  2111. if (!Array.isArray(data) || data.length === 0) { done = true; break; }
  2112. for (const item of data) {
  2113. if (!item?.name) continue;
  2114. const match = item.name.match(/^\/(\d+)([.-])/);
  2115. if (!match) continue;
  2116. const id = match[1];
  2117. if (!combinedMap[id]) combinedMap[id] = { hits: 0, bandwidth: 0 };
  2118. combinedMap[id].hits += item.hits?.total ?? 0;
  2119. combinedMap[id].bandwidth += item.bandwidth?.total ?? 0;
  2120. }
  2121. }
  2122. page += PAGE_BATCH;
  2123. }
  2124. _allStatsCache = combinedMap;
  2125. return combinedMap;
  2126. }
  2127. async function getStats(id) {
  2128. const allStats = await getAllStats();
  2129. return allStats[String(id)]?.hits ?? 0;
  2130. }
  2131. function showZoneInfo(id = Number(document.getElementById('zoneId').textContent)) {
  2132. const idjson = zones.find(a => a.id === id);
  2133. if (!idjson) return;
  2134. const body = openPopup(`${idjson.name} Info`, `<p style="margin:0;font-family:var(--f-mono);color:var(--neon);letter-spacing:.2em">LOADING…</p>`);
  2135. const r = recent.find(x => x.id === String(id));
  2136. const stats = await getStats(id);
  2137. let added = '—', adder = '—';
  2138. if (Array.isArray(json) && json.length) {
  2139. const c = json.at(-1).commit;
  2140. adder = c.author.name;
  2141. added = new Intl.DateTimeFormat("en-US", { month: "long", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit", hour12: true }).format(new Date(c.author.date));
  2142. }
  2143. body.innerHTML = `<dl class="kv">
  2144. <dt>Id</dt><dd>${esc(id)}</dd>
  2145. <dt>Name</dt><dd>${esc(idjson.name)}</dd>
  2146. ${idjson.author ? `<dt>Game Author</dt><dd>${esc(idjson.author)}</dd>` : ""}
  2147. ${idjson.authorLink ? `<dt>Author Link</dt><dd><a href="${esc(idjson.authorLink)}" target="_blank" rel="noopener">${esc(idjson.authorLink)}</a></dd>` : ""}
  2148. ${idjson.special ? `<dt>Tags</dt><dd>${esc([].concat(idjson.special).join(', '))}</dd>` : ""}
  2149. <dt>Gn-Math Adder</dt><dd>${esc(adder)}</dd>
  2150. <dt>Date Added</dt><dd>${esc(added)}</dd>
  2151. <dt>Played (Global)</dt><dd>${Number(stats).toLocaleString("en-US")}</dd>
  2152. ${r ? `<dt>Your Playtime</dt><dd>${fmtDur(r.total || 0)} over ${r.sessions || 1} session(s)</dd>` : ''}
  2153. ${saves[String(id)] ? `<dt>Your Save</dt><dd>${(saves[String(id)].keys || []).length} key(s), last write ${ago(saves[String(id)].updated)}</dd>` : ''}
  2154. </dl>`;
  2155. }).catch(err => { body.innerHTML = `<p>Could not load info: ${esc(err)}</p>`; });
  2156. }
  2157.  
  2158. /* ================= events ================= */
  2159. document.addEventListener('click', async e => {
  2160. const fav = e.target.closest('[data-fav]');
  2161. if (fav) { e.stopPropagation(); toggleFav(fav.dataset.fav); return; }
  2162. const goEl = e.target.closest('[data-go]');
  2163. if (goEl) { go(goEl.dataset.go); return; }
  2164. const tag = e.target.closest('[data-tag]');
  2165. if (tag) { ui.tag = tag.dataset.tag; render(); return; }
  2166. const rail = e.target.closest('[data-rail]');
  2167. if (rail) { const r = rail.parentElement.querySelector('.rail'); r.scrollBy({ left: Number(rail.dataset.rail) * r.clientWidth * 0.8, behavior: 'smooth' }); return; }
  2168. const open = e.target.closest('[data-open]');
  2169. if (open && !e.target.closest('[data-act]')) { if (document.getElementById('popupOverlay').classList.contains('open')) closePopup(); openZone(byId(open.dataset.open)); return; }
  2170. const act = e.target.closest('[data-act]');
  2171. if (!act) return;
  2172. const id = act.dataset.id;
  2173. switch (act.dataset.act) {
  2174. case 'settings': openSettings(); break;
  2175. case 'refresh': loadState_ = zones.length ? loadState_ : 'loading'; listZones(); break;
  2176. case 'random': playRandom(); break;
  2177. case 'close': closeZone(); break;
  2178. case 'fullscreen': fullscreenZone(); break;
  2179. case 'newtab': aboutBlank(); break;
  2180. case 'download': downloadZone(); break;
  2181. case 'info': showZoneInfo(); break;
  2182. case 'hud-fav': if (currentZone) toggleFav(currentZone.id); break;
  2183. case 'popup-close': closePopup(); break;
  2184. case 'export': closePopup(); saveData(); break;
  2185. case 'import': document.getElementById('importData').click(); break;
  2186. case 'dmca': loadDMCA(); break;
  2187. case 'contact': showContact(); break;
  2188. case 'privacy': loadPrivacy(); break;
  2189. case 'cloak-reset':
  2190. settings.cloakTitle = ''; settings.cloakIcon = ''; saveSettings(); cloakName(''); cloakIcon('');
  2191. document.getElementById('tab-cloak-title').value = ''; document.getElementById('tab-cloak-icon').value = '';
  2192. break;
  2193. case 'clear-recent':
  2194. if (await askConfirm('Clear history?', '<p style="margin-top:0">Removes your recently played list and playtime. Game saves and favorites stay.</p>', 'Clear history', true)) {
  2195. recent = []; saveRecent(); render(); toast('History cleared.', 'ok');
  2196. }
  2197. break;
  2198. case 'forget': recent = recent.filter(r => r.id !== String(id)); saveRecent(); render(); break;
  2199. case 'clear-filters': ui.tag = 'none'; ui.query = ''; searchBar.value = ''; syncSearch(); render(); break;
  2200. case 'save-details': showSaveDetails(id); break;
  2201. case 'save-export': exportGameSave(id); break;
  2202. case 'save-delete': deleteGameSave(id); break;
  2203. case 'hud-save': if (currentZone) { scanTracking(); showSaveDetails(currentZone.id); } break;
  2204. case 'save-move': {
  2205. const e = saves[id];
  2206. if (!e) break;
  2207. const from = byId(id);
  2208. openGamePicker(`Which game is this save from?`, z => {
  2209. if (!z || String(z.id) === id) return;
  2210. linkTo(String(z.id), [...(e.keys || [])], [...(e.dbs || [])]);
  2211. render();
  2212. toast(`Save moved${from ? ` from ${from.name}` : ''} to ${z.name}`, 'ok');
  2213. });
  2214. break;
  2215. }
  2216. case 'save-unlink': unlinkSave(id); closePopup(); render(); toast('Unlinked. It is listed under Unlinked data now.'); break;
  2217. case 'group-details': showGroupDetails(+act.dataset.i); break;
  2218. case 'link-group': {
  2219. const g = unlinkedGroups[+act.dataset.i];
  2220. if (!g) break;
  2221. openGamePicker(`Which game saved "${g.label}"?`, z => {
  2222. if (!z) return;
  2223. linkTo(String(z.id), g.keys, g.dbs);
  2224. render();
  2225. toast(`Linked to ${z.name}`, 'ok');
  2226. });
  2227. break;
  2228. }
  2229. case 'group-delete': {
  2230. const g = unlinkedGroups[+act.dataset.i];
  2231. if (!g) break;
  2232. if (await askConfirm('Delete this data?', `<p style="margin-top:0">Removes ${g.keys.length} key(s)${g.dbs.length ? ` and ${g.dbs.length} database(s)` : ''} under <code>${esc(g.label)}</code>. If a game uses it, that game's progress resets.</p>`, 'Delete', true)) {
  2233. g.keys.forEach(k => { try { localStorage.removeItem(k); } catch (err) {} });
  2234. g.dbs.forEach(d => { try { indexedDB.deleteDatabase(d); } catch (err) {} });
  2235. unlinkedDbs = unlinkedDbs.filter(d => !g.dbs.includes(d));
  2236. render();
  2237. toast('Deleted.', 'ok');
  2238. }
  2239. break;
  2240. }
  2241. }
  2242. });
  2243. document.addEventListener('keydown', e => {
  2244. const card = e.target.closest?.('.card[data-open]');
  2245. if (card && (e.key === 'Enter' || e.key === ' ') && e.target === card) { e.preventDefault(); openZone(byId(card.dataset.open)); return; }
  2246. if (e.key === 'Escape' && document.getElementById('popupOverlay').classList.contains('open')) { closePopup(); return; }
  2247. const typing = /^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement?.tagName);
  2248. if (e.key === '/' && !typing && !zoneViewer.classList.contains('open')) { e.preventDefault(); searchBar.focus(); }
  2249. if (e.key === 'Escape' && document.activeElement === searchBar) { searchBar.blur(); }
  2250. });
  2251. document.getElementById('popupOverlay').addEventListener('mousedown', e => { if (e.target.id === 'popupOverlay') closePopup(); });
  2252. document.getElementById('importData').addEventListener('change', loadData);
  2253.  
  2254. function syncSearch() {
  2255. const has = !!searchBar.value;
  2256. document.getElementById('searchClear').classList.toggle('hidden', !has);
  2257. document.getElementById('searchKbd').classList.toggle('hidden', has);
  2258. }
  2259. let searchT;
  2260. searchBar.addEventListener('input', () => {
  2261. syncSearch();
  2262. clearTimeout(searchT);
  2263. searchT = setTimeout(() => {
  2264. ui.query = searchBar.value;
  2265. if (ui.view !== 'games') { ui.view = 'games'; window.scrollTo(0, 0); }
  2266. render();
  2267. }, 90);
  2268. });
  2269. document.getElementById('searchClear').addEventListener('click', () => { searchBar.value = ''; ui.query = ''; syncSearch(); render(); searchBar.focus(); });
  2270.  
  2271. window.addEventListener('popstate', () => {
  2272. const id = new URLSearchParams(location.search).get('id');
  2273. if (!id && zoneViewer.classList.contains('open')) closeZone();
  2274. });
  2275. document.addEventListener('visibilitychange', () => tickPlaytime());
  2276.  
  2277. render();
  2278. listZones();
  2279.  
  2280. HTMLCanvasElement.prototype.toDataURL = function (...args) {
  2281. return "";
  2282. };
  2283. </script>
  2284. <script>
  2285. try {
  2286. const search = new URLSearchParams(window.location.search);
  2287. const privacy = search.get('privacy');
  2288. if (privacy) loadPrivacy();
  2289. } catch (error) {}
  2290. </script>
  2291. <script>
  2292. try { if ('serviceWorker' in navigator) navigator.serviceWorker.register(location.protocol + '//' + location.hostname + '/sw.js').catch(() => {}); } catch (e) {}
  2293. </script>
  2294. </body>
  2295. </html>
RAW Paste Data Copied