ntdservices commited on
Commit
04b0b69
·
verified ·
1 Parent(s): 291c7a0

Update static/embed.js

Browse files
Files changed (1) hide show
  1. static/embed.js +43 -0
static/embed.js CHANGED
@@ -1,5 +1,6 @@
1
  (() => {
2
  const API = "https://ntdservices-debt-clock.hf.space/api/debt";
 
3
 
4
  function mount(el) {
5
  Object.assign(el.style, {
@@ -41,5 +42,47 @@
41
  });
42
  }
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  document.querySelectorAll("." + CLS).forEach(mount);
45
  })();
 
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, {
 
42
  });
43
  }
44
 
45
+ document.querySelectorAll("." + CLS).forEach(mount);
46
+ })();
47
+ function mount(el) {
48
+ Object.assign(el.style, {
49
+ font: "bold 2.5rem monospace",
50
+ color: "#0f0",
51
+ background: "#000a",
52
+ padding: "12px 20px",
53
+ borderRadius: "8px",
54
+ boxShadow: "0 0 10px #0f0",
55
+ whiteSpace: "nowrap",
56
+ position: "absolute",
57
+ top: "10%",
58
+ left: "50%",
59
+ transform: "translateX(-50%)",
60
+ });
61
+
62
+ fetch(API)
63
+ .then((r) => r.json())
64
+ .then((d) => {
65
+ let debt = d.startingDebt;
66
+ const rate = d.ratePerSecond;
67
+ let last = performance.now();
68
+
69
+ function tick(now) {
70
+ const dt = (now - last) / 1000;
71
+ last = now;
72
+ debt += rate * dt;
73
+ el.textContent = "$" + debt.toLocaleString(undefined, {
74
+ minimumFractionDigits: 2,
75
+ maximumFractionDigits: 2,
76
+ });
77
+ requestAnimationFrame(tick);
78
+ }
79
+
80
+ requestAnimationFrame(tick);
81
+ })
82
+ .catch(() => {
83
+ el.textContent = "N/A";
84
+ });
85
+ }
86
+
87
  document.querySelectorAll("." + CLS).forEach(mount);
88
  })();