aboutsummaryrefslogtreecommitdiffstats
path: root/ccc.html
blob: 164d318fc4235d2d4f2b4fa25462390d8c401c1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>gumx / coffee</title>
  <link rel="icon" type="image/svg+xml" href="/favicon.svg">
  <link rel="stylesheet" href="/styles/main.css">
  <link rel="stylesheet" href="/styles/ccc.css">
</head>

<body>

  <div id="tooltip"></div>
  <div id="popover">
    <div class="pop-title" id="pop-title"></div>
    <div class="pop-row">
      <button id="pop-dec"></button>
      <input type="number" id="pop-input" min="0" max="6">
      <button id="pop-inc">+</button>
    </div>
    <div class="pop-actions">
      <button id="pop-set">set</button>
      <button id="pop-cancel">cancel</button>
    </div>
  </div>

  <header>
    <h1><a href="https://gumx.cc">gumx</a> / coffee</h1>
  </header>

  <main>

  <div id="ccc-intro">
    <p>A minimal coffee tracker. Log your daily cups and track your habits. Data lives in your browser — no account needed.</p>
  </div>

  <div class="heatmap-wrap">
    <svg id="heatmap-svg"></svg>
  </div>

  <div class="legend" id="legend"></div>

  <div id="controls" class="controls">
    <hr>
    <h2>Log</h2>
    <div class="row">
      <button id="btn-dec-log"></button>
      <span class="count-display" id="log-count-display">1</span>
      <button id="btn-inc-log">+</button>
      <button id="btn-log">log coffee</button>
    </div>
    <p class="hint">click any cell to edit that day's count</p>
    <hr>
    <h2>Data</h2>
    <div class="row">
      <button id="btn-export">export json</button>
      <button id="btn-import-trigger">import json</button>
      <input type="file" id="import-input" accept=".json,application/json">
    </div>
  </div>

  <hr>
  <h2>Stats</h2>
  <ul class="stats-list" id="stats-list">
    <li><span class="label">today</span><span class="value" id="stat-today">0 cups</span></li>
    <li><span class="label">current streak</span><span class="value" id="stat-streak">0 days</span></li>
    <li><span class="label">total cups</span><span class="value" id="stat-total">0</span></li>
    <li><span class="label">daily average</span><span class="value" id="stat-avg">0.0</span></li>
  </ul>

  </main>

  <footer>
    <hr>
    <a href="https://twt.gumx.cc">twt</a> /
    <a href="https://git.gumx.cc">git</a> /
    <a href="https://mail.gumx.cc">mail</a> /
    <a href="https://list.gumx.cc">list</a> /
    <a href="https://irc.gumx.cc">irc</a> /
    <a href="https://files.gumx.cc">files</a> /
    <a href="https://vpn.gumx.cc">vpn</a> /
    <a href="https://pgp.gumx.cc">pgp</a> /
    <a href="https://demo.gumx.cc">demo</a> /
    <a href="https://wk.fo">wk.fo</a>
    <br>
    <a href="https://git.gumx.cc/ccc">source</a> /
    <a href="https://gumx.cc/license">license</a>
  </footer>

  <script>
    // ─────────────────────────────────────────────────────────────
    // CONFIG — edit these values to configure the app
    // ─────────────────────────────────────────────────────────────
    const CONFIG = {
      DATA_URL: "data.json",   // "" = local mode | "<url>" = static site mode
      MAX_CUPS: 5,    // maximum cups allowed per day
      WEEK_START: 6,  // first day of the week: 0=Sun, 1=Mon, 2=Tue, 3=Wed, 4=Thu, 5=Fri, 6=Sat
    };
    // ─────────────────────────────────────────────────────────────

    const STORAGE_KEY = "ccc_v1";
    const CELL_SIZE = 10;
    const CELL_GAP = 1;
    const STEP = CELL_SIZE + CELL_GAP;
    const WEEKS = 53;
    const DAYS = 7;
    const LEFT_OFFSET = 28;  // space for day labels
    const TOP_OFFSET = 18;   // space for month labels

    // ── State ─────────────────────────────────────────────────────
    let entries = {};   // { "YYYY-MM-DD": count }
    let logCount = 1;
    let popoverDate = null;
    let isStaticMode = CONFIG.DATA_URL !== "";

    // ── Date utils ────────────────────────────────────────────────
    function toISO(d) {
      const y = d.getFullYear();
      const m = String(d.getMonth() + 1).padStart(2, "0");
      const day = String(d.getDate()).padStart(2, "0");
      return `${y}-${m}-${day}`;
    }

    function todayISO() {
      return toISO(new Date());
    }

    function parseDate(iso) {
      const [y, m, d] = iso.split("-").map(Number);
      return new Date(y, m - 1, d);
    }

    function addDays(d, n) {
      const r = new Date(d);
      r.setDate(r.getDate() + n);
      return r;
    }

    function formatDisplay(iso) {
      const d = parseDate(iso);
      const opts = {weekday: "short", year: "numeric", month: "short", day: "numeric"};
      return d.toLocaleDateString(undefined, opts);
    }

    // ── Color scale ───────────────────────────────────────────────
    function cellLevel(count) {
      if (!count || count <= 0) return 0;
      if (CONFIG.MAX_CUPS <= 0) return 0;
      const ratio = count / CONFIG.MAX_CUPS;
      const level = Math.round(ratio * 4);
      return Math.min(4, Math.max(1, level));
    }

    const LEVEL_VARS = ["--cell-0", "--cell-1", "--cell-2", "--cell-3", "--cell-4"];

    function getCSSColor(level) {
      return `var(${LEVEL_VARS[level]})`;
    }

    // ── Heatmap ───────────────────────────────────────────────────
    function buildHeatmap() {
      const svg = document.getElementById("heatmap-svg");
      svg.innerHTML = "";

      const today = new Date();
      today.setHours(0, 0, 0, 0);
      const todayStr = toISO(today);

      // Grid: column 0 = oldest week, column 52 = current week.
      // Rows run from WEEK_START (row 0) to WEEK_START+6 (row 6) mod 7.
      // endDate = last day of the current week (WEEK_START + 6 days from the week's start).
      const ws = ((CONFIG.WEEK_START % 7) + 7) % 7; // normalise to 0-6
      const todayDow = today.getDay(); // 0=Sun … 6=Sat
      // How many days until the end of the current week (the day before ws, mod 7)
      const daysUntilEnd = ((ws - 1 - todayDow + 7) % 7); // 0 when today IS the last day
      const endDate = addDays(today, daysUntilEnd);
      const startDate = addDays(endDate, -(WEEKS * 7 - 1)); // 53 weeks back

      const totalWidth = LEFT_OFFSET + WEEKS * STEP;
      const totalHeight = TOP_OFFSET + DAYS * STEP;

      svg.setAttribute("width", totalWidth);
      svg.setAttribute("height", totalHeight);
      svg.setAttribute("viewBox", `0 0 ${totalWidth} ${totalHeight}`);

      // ── Month labels ──────────────────────────────────────────
      let lastMonth = -1;
      for (let col = 0; col < WEEKS; col++) {
        const colStartDate = addDays(startDate, col * 7);
        const month = colStartDate.getMonth();
        if (month !== lastMonth) {
          lastMonth = month;
          const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
          const text = document.createElementNS("http://www.w3.org/2000/svg", "text");
          text.setAttribute("x", LEFT_OFFSET + col * STEP);
          text.setAttribute("y", 10);
          text.setAttribute("font-size", "9");
          text.setAttribute("fill", "var(--muted)");
          text.textContent = MONTHS[month];
          svg.appendChild(text);
        }
      }

      // ── Day labels ────────────────────────────────────────────
      // Build a 7-element label array rotated so row 0 = WEEK_START.
      // Show the label on row 1 and row 3 (alternating visible rows).
      const ALL_DAY_NAMES = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
      const DAY_LABELS = Array.from({length: 7}, (_, row) => {
        const dow = (ws + row) % 7;
        // Show label on rows 1 and 3 (skip row 0 and even rows ≥2 to avoid clutter)
        return (row === 1 || row === 3 || row === 5) ? ALL_DAY_NAMES[dow] : null;
      });
      DAY_LABELS.forEach((label, row) => {
        if (!label) return;
        const text = document.createElementNS("http://www.w3.org/2000/svg", "text");
        text.setAttribute("x", LEFT_OFFSET - 4);
        text.setAttribute("y", TOP_OFFSET + row * STEP + CELL_SIZE - 1);
        text.setAttribute("font-size", "9");
        text.setAttribute("fill", "var(--muted)");
        text.setAttribute("text-anchor", "end");
        text.textContent = label;
        svg.appendChild(text);
      });

      // ── Cells ─────────────────────────────────────────────────
      const tooltip = document.getElementById("tooltip");

      for (let col = 0; col < WEEKS; col++) {
        for (let row = 0; row < DAYS; row++) {
          const cellDate = addDays(startDate, col * 7 + row); // row 0 = week-start day
          cellDate.setHours(0, 0, 0, 0);
          if (cellDate > today) continue; // don't render future cells

          const iso = toISO(cellDate);
          const count = entries[iso] || 0;
          const level = cellLevel(count);
          const isToday = iso === todayStr;

          const x = LEFT_OFFSET + col * STEP;
          const y = TOP_OFFSET + row * STEP;

          const g = document.createElementNS("http://www.w3.org/2000/svg", "g");
          g.setAttribute("class", "cell");
          g.setAttribute("data-date", iso);
          g.setAttribute("data-count", count);

          const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
          rect.setAttribute("x", x);
          rect.setAttribute("y", y);
          rect.setAttribute("width", CELL_SIZE);
          rect.setAttribute("height", CELL_SIZE);
          rect.setAttribute("rx", "2");
          rect.setAttribute("fill", getCSSColor(level));

          if (isToday) {
            rect.setAttribute("stroke", "var(--today-outline)");
            rect.setAttribute("stroke-width", "1.5");
          }

          g.appendChild(rect);

          // Tooltip events
          g.addEventListener("mouseenter", (e) => {
            const cups = entries[iso] || 0;
            const label = cups === 1 ? "cup" : "cups";
            tooltip.textContent = `${formatDisplay(iso)}${cups} ${label}`;
            tooltip.style.display = "block";
            positionTooltip(e);
          });
          g.addEventListener("mousemove", positionTooltip);
          g.addEventListener("mouseleave", () => {
            tooltip.style.display = "none";
          });

          // Click to edit (local mode only)
          if (!isStaticMode) {
            g.addEventListener("click", (e) => {
              e.stopPropagation();
              openPopover(iso, e.target);
            });
          }

          svg.appendChild(g);
        }
      }
    }

    function positionTooltip(e) {
      const tooltip = document.getElementById("tooltip");
      const margin = 12;
      let x = e.clientX + margin;
      let y = e.clientY + margin;
      const tw = tooltip.offsetWidth;
      const th = tooltip.offsetHeight;
      if (x + tw > window.innerWidth - 8) x = e.clientX - tw - margin;
      if (y + th > window.innerHeight - 8) y = e.clientY - th - margin;
      tooltip.style.left = x + "px";
      tooltip.style.top = y + "px";
    }

    // ── Legend ────────────────────────────────────────────────────
    function buildLegend() {
      const legend = document.getElementById("legend");
      legend.innerHTML = "";

      const span0 = document.createElement("span");
      span0.style.color = "var(--muted)";
      span0.style.fontSize = "0.75rem";
      span0.textContent = "less";
      legend.appendChild(span0);

      for (let i = 0; i <= 4; i++) {
        const swatch = document.createElement("span");
        swatch.className = "legend-swatch";
        swatch.style.background = `var(${LEVEL_VARS[i]})`;
        if (i === 0) {
          swatch.style.border = "1px solid var(--border)";
        }
        legend.appendChild(swatch);
      }

      const span1 = document.createElement("span");
      span1.style.color = "var(--muted)";
      span1.style.fontSize = "0.75rem";
      span1.textContent = `more (max ${CONFIG.MAX_CUPS})`;
      legend.appendChild(span1);
    }

    // ── Stats ─────────────────────────────────────────────────────
    function updateStats() {
      const today = todayISO();
      const todayCups = entries[today] || 0;

      document.getElementById("stat-today").textContent =
        `${todayCups} / ${CONFIG.MAX_CUPS} cup${todayCups === 1 ? "" : "s"}`;

      // Streak: consecutive days with at least 1 cup, ending today or yesterday
      let streak = 0;
      let check = new Date();
      check.setHours(0, 0, 0, 0);

      // If today has no cups, start from yesterday
      if (!entries[today]) {
        check = addDays(check, -1);
      }

      while (true) {
        const iso = toISO(check);
        if (entries[iso] && entries[iso] > 0) {
          streak++;
          check = addDays(check, -1);
        } else {
          break;
        }
      }

      document.getElementById("stat-streak").textContent =
        `${streak} day${streak === 1 ? "" : "s"}`;

      const allDates = Object.keys(entries).filter(k => entries[k] > 0);
      const totalCups = allDates.reduce((s, k) => s + entries[k], 0);
      const activeDays = allDates.length;
      const avg = activeDays > 0 ? (totalCups / activeDays).toFixed(1) : "0.0";

      document.getElementById("stat-total").textContent = totalCups;
      document.getElementById("stat-avg").textContent = `${avg} cups/day`;
    }

    // ── Controls ──────────────────────────────────────────────────
    function updateLogButtons() {
      const today = todayISO();
      const todayCups = entries[today] || 0;
      const remaining = CONFIG.MAX_CUPS - todayCups;

      const btnDec = document.getElementById("btn-dec-log");
      const btnInc = document.getElementById("btn-inc-log");
      const btnLog = document.getElementById("btn-log");
      const display = document.getElementById("log-count-display");

      // clamp logCount
      if (logCount < 1) logCount = 1;
      if (logCount > 10) logCount = 10;
      if (logCount > remaining) logCount = Math.max(1, remaining);

      display.textContent = logCount;

      btnDec.disabled = logCount <= 1;
      btnInc.disabled = logCount >= remaining || logCount >= 10;
      btnLog.disabled = remaining <= 0;
    }

    document.getElementById("btn-dec-log").addEventListener("click", () => {
      logCount = Math.max(1, logCount - 1);
      updateLogButtons();
    });

    document.getElementById("btn-inc-log").addEventListener("click", () => {
      const today = todayISO();
      const todayCups = entries[today] || 0;
      const remaining = CONFIG.MAX_CUPS - todayCups;
      logCount = Math.min(10, Math.min(remaining, logCount + 1));
      updateLogButtons();
    });

    document.getElementById("btn-log").addEventListener("click", () => {
      const today = todayISO();
      const current = entries[today] || 0;
      const newVal = Math.min(CONFIG.MAX_CUPS, current + logCount);
      if (newVal > 0) {
        entries[today] = newVal;
      }
      saveData();
      refresh();
    });

    // ── Popover ───────────────────────────────────────────────────
    function openPopover(iso, targetEl) {
      const popover = document.getElementById("popover");
      const input = document.getElementById("pop-input");
      const title = document.getElementById("pop-title");

      popoverDate = iso;
      const current = entries[iso] || 0;

      title.textContent = formatDisplay(iso);
      input.value = current;
      input.max = CONFIG.MAX_CUPS;
      updatePopoverButtons();

      // Position near the cell
      const svgEl = document.getElementById("heatmap-svg");
      const svgRect = svgEl.getBoundingClientRect();
      const targetRect = targetEl.closest("g").getBoundingClientRect
        ? targetEl.getBoundingClientRect()
        : svgRect;

      const scrollTop = window.scrollY || document.documentElement.scrollTop;
      const scrollLeft = window.scrollX || document.documentElement.scrollLeft;

      let px = targetRect.left + scrollLeft + CELL_SIZE + 4;
      let py = targetRect.top + scrollTop;

      popover.style.display = "block";

      // After display, check bounds
      const pw = popover.offsetWidth;
      const ph = popover.offsetHeight;
      const maxLeft = scrollLeft + window.innerWidth - pw - 8;
      const maxTop = scrollTop + window.innerHeight - ph - 8;

      if (px > maxLeft) px = targetRect.left + scrollLeft - pw - 4;
      if (py > maxTop) py = maxTop;
      if (py < scrollTop + 4) py = scrollTop + 4;

      popover.style.left = px + "px";
      popover.style.top = py + "px";

      input.focus();
      input.select();
    }

    function closePopover() {
      document.getElementById("popover").style.display = "none";
      popoverDate = null;
    }

    function updatePopoverButtons() {
      const input = document.getElementById("pop-input");
      const val = parseInt(input.value) || 0;
      document.getElementById("pop-dec").disabled = val <= 0;
      document.getElementById("pop-inc").disabled = val >= CONFIG.MAX_CUPS;
    }

    document.getElementById("pop-dec").addEventListener("click", () => {
      const input = document.getElementById("pop-input");
      const val = Math.max(0, (parseInt(input.value) || 0) - 1);
      input.value = val;
      updatePopoverButtons();
    });

    document.getElementById("pop-inc").addEventListener("click", () => {
      const input = document.getElementById("pop-input");
      const val = Math.min(CONFIG.MAX_CUPS, (parseInt(input.value) || 0) + 1);
      input.value = val;
      updatePopoverButtons();
    });

    document.getElementById("pop-input").addEventListener("input", updatePopoverButtons);

    document.getElementById("pop-set").addEventListener("click", () => {
      if (!popoverDate) return;
      const val = parseInt(document.getElementById("pop-input").value) || 0;
      if (val <= 0) {
        delete entries[popoverDate];
      } else {
        entries[popoverDate] = Math.min(CONFIG.MAX_CUPS, val);
      }
      saveData();
      closePopover();
      refresh();
    });

    document.getElementById("pop-cancel").addEventListener("click", closePopover);

    document.getElementById("pop-input").addEventListener("keydown", (e) => {
      if (e.key === "Enter") document.getElementById("pop-set").click();
      if (e.key === "Escape") closePopover();
    });

    document.addEventListener("keydown", (e) => {
      if (e.key === "Escape" && popoverDate) closePopover();
    });

    document.addEventListener("click", (e) => {
      const popover = document.getElementById("popover");
      if (popover.style.display !== "none" && !popover.contains(e.target)) {
        closePopover();
      }
    });

    // ── Export / Import ───────────────────────────────────────────
    document.getElementById("btn-export").addEventListener("click", () => {
      const data = JSON.stringify({entries}, null, 2);
      const blob = new Blob([data], {type: "application/json"});
      const url = URL.createObjectURL(blob);
      const a = document.createElement("a");
      a.href = url;
      a.download = "ccc-data.json";
      a.click();
      URL.revokeObjectURL(url);
    });

    document.getElementById("btn-import-trigger").addEventListener("click", () => {
      document.getElementById("import-input").click();
    });

    document.getElementById("import-input").addEventListener("change", (e) => {
      const file = e.target.files[0];
      if (!file) return;
      const reader = new FileReader();
      reader.onload = (ev) => {
        try {
          const parsed = JSON.parse(ev.target.result);
          if (parsed && typeof parsed.entries === "object") {
            entries = {};
            for (const [k, v] of Object.entries(parsed.entries)) {
              if (/^\d{4}-\d{2}-\d{2}$/.test(k) && typeof v === "number" && v > 0) {
                entries[k] = Math.min(CONFIG.MAX_CUPS, v);
              }
            }
            saveData();
            refresh();
          } else {
            alert("Invalid data format. Expected { \"entries\": { ... } }");
          }
        } catch {
          alert("Failed to parse JSON file.");
        }
      };
      reader.readAsText(file);
      e.target.value = "";
    });

    // ── Storage ───────────────────────────────────────────────────
    function saveData() {
      if (isStaticMode) return;
      localStorage.setItem(STORAGE_KEY, JSON.stringify({entries}));
    }

    function loadLocalData() {
      const raw = localStorage.getItem(STORAGE_KEY);
      if (!raw) return;
      try {
        const parsed = JSON.parse(raw);
        if (parsed && typeof parsed.entries === "object") {
          entries = {};
          for (const [k, v] of Object.entries(parsed.entries)) {
            if (/^\d{4}-\d{2}-\d{2}$/.test(k) && typeof v === "number" && v > 0) {
              entries[k] = v;
            }
          }
        }
      } catch {
        entries = {};
      }
    }

    async function loadRemoteData() {
      try {
        const res = await fetch(CONFIG.DATA_URL);
        if (!res.ok) throw new Error(`HTTP ${res.status}`);
        const parsed = await res.json();
        if (parsed && typeof parsed.entries === "object") {
          entries = {};
          for (const [k, v] of Object.entries(parsed.entries)) {
            if (/^\d{4}-\d{2}-\d{2}$/.test(k) && typeof v === "number" && v > 0) {
              entries[k] = v;
            }
          }
        }
      } catch (err) {
        console.error("ccc: failed to load data from", CONFIG.DATA_URL, err);
      }
    }

    // ── Render ────────────────────────────────────────────────────
    function refresh() {
      buildHeatmap();
      buildLegend();
      updateStats();
      if (!isStaticMode) updateLogButtons();
    }

    // ── Dark mode observer ────────────────────────────────────────
    const darkMQ = window.matchMedia("(prefers-color-scheme: dark)");
    darkMQ.addEventListener("change", () => {
      // Re-render SVG so CSS vars re-apply (SVG fill="var(...)" doesn't
      // automatically repaint on MQ change in some browsers)
      refresh();
    });

    // ── Init ──────────────────────────────────────────────────────
    async function init() {
      if (isStaticMode) {
        document.getElementById("controls").style.display = "none";
        await loadRemoteData();
      } else {
        loadLocalData();
      }
      refresh();
    }

    init();
  </script>
</body>

</html>