<?php
require_once __DIR__ . '/includes/nowplaying_lib.php';
$track = htmlspecialchars(smurf_fetch_nowplaying_title(), ENT_QUOTES, 'UTF-8');
?>
<span id="track-text"><?= $track ?></span>
<script>
(function(){
  if (window.__tmrHomeNowPlayingInit) return;
  window.__tmrHomeNowPlayingInit = true;
  async function refreshHomeNowPlaying(){
    try{
      const res = await fetch('/api/nowplaying.php?ts=' + Date.now(), {cache:'no-store'});
      if(!res.ok) return;
      const data = await res.json();
      const el = document.getElementById('track-text');
      if(el && data && data.title){ el.textContent = data.title; }
    }catch(e){}
  }
  setInterval(refreshHomeNowPlaying, 30000);
})();
</script>
