54 lines
2.4 KiB
JavaScript
54 lines
2.4 KiB
JavaScript
// ── PROGRAM MODAL ─────────────────────────────────────────────────────────────
|
|
function openProgramModal(ch, p) {
|
|
const now = new Date();
|
|
const isLive = p.start <= now && p.stop > now;
|
|
const dur = Math.round((p.stop - p.start) / 60000);
|
|
const ep = fmtEpisode(p.season, p.episode);
|
|
const genres = formatCategories(p.categories);
|
|
const meta = [p.airDate, p.rating].filter(Boolean).join(' · ');
|
|
|
|
document.getElementById('pm-title').textContent = p.title;
|
|
document.getElementById('pm-channel').textContent = ch.name;
|
|
document.getElementById('pm-subtitle').textContent = p.subtitle || '';
|
|
document.getElementById('pm-subtitle').style.display = p.subtitle ? 'block' : 'none';
|
|
document.getElementById('pm-time').textContent =
|
|
`${fmtTime(p.start)} — ${fmtTime(p.stop)} · ${dur} ${L.duration_min}` +
|
|
(ep ? ` · ${ep}` : '');
|
|
document.getElementById('pm-meta').textContent = meta;
|
|
document.getElementById('pm-meta').style.display = meta ? 'block' : 'none';
|
|
document.getElementById('pm-genres').textContent = genres;
|
|
document.getElementById('pm-genres').style.display = genres ? 'block' : 'none';
|
|
document.getElementById('pm-desc').textContent = p.desc || '';
|
|
document.getElementById('pm-desc').style.display = p.desc ? 'block' : 'none';
|
|
|
|
// Only show "Watch now" when the program is live and the active source has M3U data.
|
|
const watchBtn = document.getElementById('pm-watch');
|
|
if (isLive && currentM3uUrl) {
|
|
watchBtn.style.display = 'inline-flex';
|
|
watchBtn.onclick = () => { closeProgramModal(); openPip(ch.name, p.title); };
|
|
} else {
|
|
watchBtn.style.display = 'none';
|
|
}
|
|
|
|
// IMDb search shortcut.
|
|
document.getElementById('pm-imdb').href =
|
|
`https://www.imdb.com/find/?q=${encodeURIComponent(p.title)}&s=tt`;
|
|
|
|
document.getElementById('programModal').classList.add('visible');
|
|
}
|
|
|
|
function closeProgramModal() {
|
|
document.getElementById('programModal').classList.remove('visible');
|
|
}
|
|
|
|
// Close when the overlay itself is clicked.
|
|
document.addEventListener('click', e => {
|
|
const modal = document.getElementById('programModal');
|
|
if (e.target === modal) closeProgramModal();
|
|
});
|
|
|
|
// Close on Escape.
|
|
document.addEventListener('keydown', e => {
|
|
if (e.key === 'Escape') closeProgramModal();
|
|
});
|