ntdservices commited on
Commit
3954f87
Β·
verified Β·
1 Parent(s): 7ac8c92

Update static/embed.js

Browse files
Files changed (1) hide show
  1. static/embed.js +39 -22
static/embed.js CHANGED
@@ -1,47 +1,64 @@
 
1
  (() => {
2
  const API = "https://ntdservices-debt-clock.hf.space/api/debt";
3
  const CLS = "ntd-debt-clock";
4
 
 
 
 
 
 
 
 
 
 
 
5
  function mount(el) {
6
  Object.assign(el.style, {
7
- font: "bold 2.5rem monospace",
8
- color: "#0f0",
9
- background: "#000a",
10
- padding: "12px 20px",
11
- borderRadius: "8px",
12
- boxShadow: "0 0 10px #0f0",
13
  whiteSpace: "nowrap",
 
14
  position: "absolute",
15
- top: "10%",
16
  left: "50%",
17
- transform: "translateX(-50%)",
 
18
  });
19
 
 
20
  fetch(API)
21
- .then((r) => r.json())
22
- .then((d) => {
23
  let debt = d.startingDebt;
24
  const rate = d.ratePerSecond;
25
  let last = performance.now();
26
 
27
- function tick(now) {
28
- const dt = (now - last) / 1000;
 
 
29
  last = now;
30
  debt += rate * dt;
31
- el.textContent = "$" + debt.toLocaleString(undefined, {
32
- minimumFractionDigits: 2,
33
- maximumFractionDigits: 2,
34
- });
35
- requestAnimationFrame(tick);
36
- }
37
 
38
- requestAnimationFrame(tick);
 
 
 
 
 
 
 
39
  })
40
- .catch((err) => {
41
- console.error("Failed to fetch debt:", err);
42
  el.textContent = "N/A";
43
  });
44
  }
45
 
46
  document.querySelectorAll("." + CLS).forEach(mount);
47
- })();
 
1
+ /* embed.js –– digital-clock styling */
2
  (() => {
3
  const API = "https://ntdservices-debt-clock.hf.space/api/debt";
4
  const CLS = "ntd-debt-clock";
5
 
6
+ /* ── 1. load a free 7-segment web-font once per page ───────────── */
7
+ if (!document.getElementById("dseg-font")) {
8
+ const link = document.createElement("link");
9
+ link.id = "dseg-font";
10
+ link.rel = "stylesheet";
11
+ link.href = "https://cdn.jsdelivr.net/npm/@fontsource-variable/dseg7-classic/index.min.css";
12
+ document.head.appendChild(link);
13
+ }
14
+
15
+ /* ── 2. mount logic ─────────────────────────────────────────────── */
16
  function mount(el) {
17
  Object.assign(el.style, {
18
+ font: "900 5.5rem 'DSEG7 Classic', monospace",
19
+ color: "#ffb400", // amber LEDs
20
+ textShadow: "0 0 6px rgba(255,180,0,.8)",
21
+ background: "rgba(0,0,0,.65)",
22
+ padding: "8px 14px",
23
+ borderRadius: "6px",
24
  whiteSpace: "nowrap",
25
+ letterSpacing: ".08em",
26
  position: "absolute",
27
+ top: "40%",
28
  left: "50%",
29
+ transform: "translate(-50%, -50%)",
30
+ userSelect: "none",
31
  });
32
 
33
+ /* fetch current debt + per-second rate */
34
  fetch(API)
35
+ .then(r => r.json())
36
+ .then(d => {
37
  let debt = d.startingDebt;
38
  const rate = d.ratePerSecond;
39
  let last = performance.now();
40
 
41
+ /* update 4Γ—/sec for a mild β€œtick” */
42
+ setInterval(() => {
43
+ const now = performance.now();
44
+ const dt = (now - last) / 1000;
45
  last = now;
46
  debt += rate * dt;
 
 
 
 
 
 
47
 
48
+ /* split into 3-digit groups to mimic signage */
49
+ const parts = Math.round(debt)
50
+ .toString()
51
+ .replace(/\B(?=(\d{3})+(?!\d))/g, ",")
52
+ .split(",");
53
+
54
+ el.textContent = "$" + parts.join(",");
55
+ }, 250);
56
  })
57
+ .catch(err => {
58
+ console.error("Debt fetch failed:", err);
59
  el.textContent = "N/A";
60
  });
61
  }
62
 
63
  document.querySelectorAll("." + CLS).forEach(mount);
64
+ })();