click to enter...
DEX

DEX

@dex
Discord avatar
DEX
@dex
OFFLINE
Loading Discord...
/* Discord-style activity elapsed timer */ (() => { const elapsedEl = document.getElementById("discordElapsed"); if (!elapsedEl) return; let timer = null; let startMs = 0; let activityKey = ""; function formatElapsed(ms) { const total = Math.max(0, Math.floor(ms / 1000)); const days = Math.floor(total / 86400); const hours = Math.floor((total % 86400) / 3600); const minutes = Math.floor((total % 3600) / 60); const seconds = total % 60; if (days) return `${days}d ${hours}h ${String(minutes).padStart(2, "0")}m`; if (hours) return `${hours}h ${String(minutes).padStart(2, "0")}m ${String(seconds).padStart(2, "0")}s`; if (minutes) return `${minutes}m ${String(seconds).padStart(2, "0")}s`; return `${seconds}s`; } function getTimestampMs(value) { if (value == null) return 0; if (typeof value === "object") value = value.value ?? value.timestamp ?? value.ms ?? value.start ?? 0; if (typeof value === "string") { const parsed = Date.parse(value); if (Number.isFinite(parsed)) return parsed; const numeric = Number(value); if (Number.isFinite(numeric)) value = numeric; else return 0; } const n = Number(value); if (!Number.isFinite(n) || n <= 0) return 0; return n < 100000000000 ? n * 1000 : n; } function sourceStart(source) { if (!source) return 0; const t = source.timestamps || source.timestamp || {}; return getTimestampMs(t.start) || getTimestampMs(source.startTimestamp) || getTimestampMs(source.start_time) || getTimestampMs(source.startedAt) || getTimestampMs(source.start) || getTimestampMs(source.startTime); } function sourceKey(source, type) { if (!source) return ""; const application = source.application_id || source.applicationId || ""; return [type, application, source.name || "", source.details || "", source.state || "", source.song || "", source.artist || ""].join("|"); } function hide() { if (timer) clearInterval(timer); timer = null; startMs = 0; activityKey = ""; elapsedEl.textContent = ""; elapsedEl.classList.remove("visible"); } function render() { if (!startMs) return; const elapsed = Math.max(0, Date.now() - startMs); elapsedEl.textContent = `For ${formatElapsed(elapsed)}`; elapsedEl.classList.add("visible"); } window.updateDiscordElapsed = function(activity, spotify) { const source = activity || spotify; if (!source) { hide(); return; } const type = activity ? "activity" : "spotify"; const key = sourceKey(source, type); const timestamp = sourceStart(source); // Discord's own elapsed counter is based on the activity's start timestamp. // If a brand-new activity arrives without one, start at the moment we detect it. if (key !== activityKey) { activityKey = key; startMs = timestamp || Date.now(); if (timer) clearInterval(timer); timer = setInterval(render, 1000); } else if (timestamp && Math.abs(timestamp - startMs) > 1000) { startMs = timestamp; } render(); }; window.clearDiscordElapsed = hide; })();