Spaces:
Sleeping
Sleeping
File size: 2,003 Bytes
ade6e08 6afb0c7 c318a2c 6afb0c7 c318a2c 629d720 c318a2c 629d720 c318a2c 629d720 c318a2c 629d720 3954f87 c318a2c 6afb0c7 04b0b69 1374d1f 629d720 c318a2c e83a700 629d720 3954f87 69d38fb 32bae9a 3954f87 c318a2c 04b0b69 ade6e08 04b0b69 c318a2c ade6e08 c318a2c 3954f87 c318a2c ade6e08 c318a2c ade6e08 c318a2c ade6e08 c318a2c 6172e7c be7ad51 6afb0c7 3954f87 |
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 |
/* embed.js – discrete 4Hz ticking version */
(() => {
const API = "https://ntdservices-debt-clock.hf.space/api/debt";
const CLS = "ntd-debt-clock";
const REFRESH_MS = 5 * 60 * 1000; // poll backend every 5 min
/* 1 ▸ inject DSEG-7 font once per page */
if (!document.getElementById("dseg-face")) {
const style = document.createElement("style");
style.id = "dseg-face";
style.textContent = `
@font-face {
font-family: "DSEG7";
src: url("https://cdn.jsdelivr.net/npm/@fontsource/dseg7-classic/files/dseg7-classic-latin-700-normal.woff2")
format("woff2");
font-weight: 700;
font-style: normal;
font-display: swap;
}`;
document.head.appendChild(style);
}
/* 2 ▸ mount one clock per matching element */
function mount(el) {
Object.assign(el.style, {
font: "700 5.5rem 'DSEG7', monospace",
color: "#ffb400",
textShadow: "0 0 8px rgba(255,180,0,.9)",
background: "transparent",
padding: "10px 18px",
borderRadius: "6px",
whiteSpace: "pre",
letterSpacing: ".6em",
userSelect: "none",
position: "relative",
});
let baseDebt = 0;
let ratePerSec = 0;
let baseTime = Date.now();
async function pull() {
try {
const d = await fetch(API).then(r => r.json());
baseDebt = d.startingDebt;
ratePerSec = d.ratePerSecond;
baseTime = Date.now();
} catch (err) {
console.error("Debt fetch failed:", err);
}
}
pull();
setInterval(pull, REFRESH_MS);
/* update 4×/sec (every 250ms) */
setInterval(() => {
const now = Date.now();
const delta = (now - baseTime) / 1000;
const debt = baseDebt + ratePerSec * delta;
el.textContent =
Math.round(debt).toLocaleString("en-US").replace(/,/g, " ");
}, 250);
}
document.querySelectorAll("." + CLS).forEach(mount);
})();
|