const selectionCard = document.querySelector('[data-selection-url]') const selectionName = document.getElementById('home-selection') const selectionDetail = document.getElementById('home-selection-detail') function updateSelectionText(element, text) { // Avoid repeated screen-reader announcements when the selection hasn't changed. if (element.textContent !== text) element.textContent = text } async function refreshHomeSelection() { try { const response = await fetch(selectionCard.dataset.selectionUrl, {cache: 'no-store'}) if (!response.ok) throw new Error('Selection unavailable') const state = await response.json() updateSelectionText(selectionName, state.blank ? 'Blank screen selected' : state.selected_name) updateSelectionText(selectionDetail, state.using_default && !state.blank ? 'Default selection. The player runs separately on your display.' : 'This is the requested selection; the player runs separately on your display.') } catch (error) { updateSelectionText(selectionName, 'Selection unavailable') updateSelectionText(selectionDetail, 'Open the media library to try again.') } finally { window.setTimeout(refreshHomeSelection, 5000) } } refreshHomeSelection()