Website: "Playing now" on the home page, from the telemetry server's live count
The home page's "At a glance" list gets a fifth row with how many play right now, read from https://telemetry.playhorizon.dev/v1/live (3 s timeout, again every minute while the tab is visible). It stays hidden while nobody plays or the server doesn't answer. The FAQ no longer says the "I'm playing" ping is off: the server is live since #1276. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -96,6 +96,7 @@
|
||||
<li class="row reveal"><a href="#parity"><span class="row-index">02</span><span class="row-name">Differential harnesses</span><span class="row-meta">{{HARNESSES}}</span></a></li>
|
||||
<li class="row reveal"><a href="#screenshots"><span class="row-index">03</span><span class="row-name">Drawn by Horizon</span><span class="row-meta">5 shots</span></a></li>
|
||||
<li class="row reveal"><a href="#recent"><span class="row-index">04</span><span class="row-name">Recently added</span><span class="row-meta">Releases</span></a></li>
|
||||
<li class="row reveal" data-live hidden><a href="/privacy"><span class="row-index">05</span><span class="row-name">Playing now</span><span class="row-meta" data-live-count></span></a></li>
|
||||
</ol>
|
||||
<p class="disclaimer reveal">Unofficial. Not an official Minecraft product. Not approved by or associated with Mojang or Microsoft.</p>
|
||||
</div>
|
||||
|
||||
+31
-1
@@ -1,5 +1,6 @@
|
||||
// The page's behaviour: the download buttons for this platform, the latest releases, the
|
||||
// links and contributors, the navigation, the menus' tabs, the lightbox and the motion.
|
||||
// links and contributors, how many play now, the navigation, the menus' tabs, the lightbox
|
||||
// and the motion.
|
||||
// Everything degrades to the baked-in content when GitHub can't be reached.
|
||||
import { escape } from "./markdown.js";
|
||||
import { recentHtml } from "./releases.js";
|
||||
@@ -103,6 +104,34 @@ async function setUpLinks() {
|
||||
});
|
||||
}
|
||||
|
||||
// --- Playing now ---------------------------------------------------------------------
|
||||
|
||||
const TELEMETRY = "https://telemetry.playhorizon.dev";
|
||||
|
||||
// How many play right now, from the games' anonymous "I'm playing" pings (Privacy explains them). The
|
||||
// server rounds it and makes it again at most every 15 seconds; the row stays hidden while nobody plays
|
||||
// or the server doesn't answer.
|
||||
async function setUpLive() {
|
||||
const row = document.querySelector("[data-live]");
|
||||
if (!row) return;
|
||||
const update = async () => {
|
||||
try {
|
||||
const res = await fetch(`${TELEMETRY}/v1/live`, { signal: AbortSignal.timeout(3000) });
|
||||
if (!res.ok) throw new Error(String(res.status));
|
||||
const { playing } = await res.json();
|
||||
if (!Number.isInteger(playing) || playing < 1) throw new Error("nobody");
|
||||
row.querySelector("[data-live-count]").textContent = playing.toLocaleString("en");
|
||||
row.hidden = false;
|
||||
// It shows up after the others came in, so it skips their entrance.
|
||||
row.classList.add("is-visible");
|
||||
} catch {
|
||||
row.hidden = true;
|
||||
}
|
||||
};
|
||||
await update();
|
||||
setInterval(() => document.visibilityState === "visible" && update(), 60_000);
|
||||
}
|
||||
|
||||
// --- Navigation ----------------------------------------------------------------------
|
||||
|
||||
function setUpNav() {
|
||||
@@ -235,3 +264,4 @@ setUpDownload();
|
||||
setUpRecent();
|
||||
setUpLinks();
|
||||
setUpContributors();
|
||||
setUpLive();
|
||||
|
||||
Reference in New Issue
Block a user