···
<script type="text/javascript">
+
// We'll store the last title of the current mount point to check for changes
+
// Store the current mount point
+
// Store the last notification
+
let lastNotification = null
+
// On every audio element, create a new Plyr instance
+
document.querySelectorAll('div[data-mount]').forEach((e) => {
+
e.querySelector('audio'),
+
controls: ['play', 'current-time', 'mute', 'volume'],
+
// When we start playing, store current mount point, clear last title and stop all other players
+
currentMount = e.dataset.mount
+
document.querySelectorAll('[data-mount]').forEach((a) => {
+
a.querySelector('audio').stop()
+
// When we pause, clear current mount point and stop all data
+
// To prevent overlaps, we only clear the current mount if it's the same as the one we're pausing
+
if (currentMount === e.dataset.mount) {
+
// Find all mount points and fetch their status
+
document.querySelectorAll('div[data-mount]').forEach((e) => {
fetch('./status-json.xsl?mount=' + e.dataset.mount)
+
// We delay the update to match the usual delay of the audio stream
+
// The title may not be present, so we check for it
if (j.icestats.source.title) {
+
// Update the now playing text
e.querySelector('.playing').innerHTML = j.icestats.source.title
+
// If the title has changed and this is our current playing mount
+
if (lastTitle !== j.icestats.source.title && currentMount === e.dataset.mount) {
+
// Update the last title
+
lastTitle = j.icestats.source.title
+
// If we have permission, send a notification
+
if ('Notification' in window && Notification.permission === 'granted') {
+
lastNotification = new Notification(
+
body: j.icestats.source.title,
+
icon: 'https://rita.moe/rita-icon.png',
+
requireInteraction: false,
+
// If the title is not present, clear the now playing text
e.querySelector('.playing').innerHTML = ''
···
+
// Enable interval to fetch now playing data
+
// And run it immediately on page load
+
// Request notification permission if it's still default
+
if ('Notification' in window && Notification.permission === 'default') {
+
Notification.requestPermission()
+
document.addEventListener(
+
// If the page is visible, close the last notification
+
if (document.visibilityState === 'visible') {
+
lastNotification?.close()