(() => {
"use strict";
const list = document.getElementById("ymHistory");
const updated = document.getElementById("ymUpdated");
const refresh = document.getElementById("ymRefresh");
const nowBody = document.getElementById("ymNowBody");
const nowEl = document.getElementById("ymNow");
if (!list || !updated) return;
const SOURCE = "/api/listenbrainz/recent";
const NOW_SOURCE = "/api/listenbrainz/now";
const POLL_MS = 30000;
const NOW_POLL_MS = 10000;
let timer = null;
let nowTimer = null;
let busy = false;
let nowBusy = false;
const seen = new Set();
let firstLoad = true;
const escapeHtml = (s) =>
String(s).replace(/[&<>"']/g, (c) => ({
"&": "&", "<": "<", ">": ">", '"': """, "'": "'",
})[c]);
const dayLabel = (t) => {
if (t.nowplaying) return "сейчас";
if (!t.day) return "";
const today = new Date().toISOString().slice(0, 10);
const yest = new Date(Date.now() - 86400000).toISOString().slice(0, 10);
if (t.day === today) return "сегодня";
if (t.day === yest) return "вчера";
const [y, m, d] = t.day.split("-");
return `${d}.${m}.${y}`;
};
const render = (tracks) => {
const fresh = [];
const html = tracks.map((t) => {
const key = `${t.id}:${t.album_id || ""}:${t.day || ""}`;
if (!seen.has(key)) {
seen.add(key);
if (!firstLoad) fresh.push(key);
}
const isNew = fresh.includes(key);
const cover = t.cover
? ``
: ``;
const artists = (t.artists || []).map(escapeHtml).join(", ");
const context = t.context ? ` · ${escapeHtml(t.context)}` : "";
const link = t.url
? ``
: `
`
: ``;
const artists = (track.artists || []).map(escapeHtml).join(", ");
const context = track.context ? ` · ${escapeHtml(track.context)}` : "";
const inner = `
${cover}
${escapeHtml(track.title)}
${artists || "—"}${context}
`;
nowBody.innerHTML = track.url
? `${inner}`
: `