ntdservices commited on
Commit
cb0abd4
·
verified ·
1 Parent(s): 82295c8

Upload embed.js

Browse files
Files changed (1) hide show
  1. templates/embed.js +46 -0
templates/embed.js ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (() => {
2
+ const API = "/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(() => {
41
+ el.textContent = "N/A";
42
+ });
43
+ }
44
+
45
+ document.querySelectorAll("." + CLS).forEach(mount);
46
+ })();