PageSourceSearch

https://kwrsradio.org/wp-content/plugins/icecast-audio-player/script.js?ver=1.0

js kwrsradio.org collected 2026-10-02 01:06:56 UTC 4,228 bytes, 113 lines download raw bytes

1document.addEventListener("DOMContentLoaded", function() {
2    fetchMetadata();
3    setInterval(fetchMetadata, 3000);
4});
5
6// Fetching metadata from the Icecast server
7function fetchMetadata() {
8    var mountpoint = document.getElementById('metadata').dataset.mountpoint;
9    var audio_host = document.getElementById('metadata').dataset.audio_host;
10    var targetUrl = audio_host + '/status-json.xsl';
11
12    fetch(targetUrl)
13    .then(response => {
14        // Check if the content type is XML or JSON, then parse accordingly
15        var contentType = response.headers.get("content-type");
16        if (contentType && contentType.indexOf("application/json") !== -1) {
17            return response.json();
18        } else if (contentType && contentType.indexOf("application/xml") !== -1) {
19            return response.text().then(str => (new window.DOMParser()).parseFromString(str, "text/xml"));
20        } else {
21            throw new TypeError("Oops, we haven't got JSON or XML!");
22        }
23    })
24    .then(data => {
25        // Handle JSON or XML data here
26        if (data instanceof Document) { // The data is XML
27            const title = data.getElementsByTagName("title")[0].textContent;
28            document.getElementById('currentTrack').textContent = "Now Playing: " + title;
29        } else { // The data is JSON
30            let sources = data.icestats.source;
31    
32            // Check if sources is an array, if not make it an array
33            if (!Array.isArray(sources)) {
34                sources = [sources]; // Create an array with the single source object
35            }
36    
37            let streamInfo;
38            for (let i = 0; i < sources.length; i++) {
39                if (sources[i].listenurl.includes('/' + mountpoint)) {
40                    streamInfo = sources[i];
41                    break;
42                }
43            }
44            if (streamInfo) {
45                document.getElementById('currentTrack').textContent = "Now Playing: " + streamInfo.title;
46            } else {
47                console.error('Mountpoint not found. Mountpoint: ' + mountpoint);
48            }
49        }
50    })
51    .catch(error => console.error('Error fetching metadata:', error));
52}
53
54document.addEventListener('DOMContentLoaded', (event) => {
55    const audioElement = document.getElementById("audio");
56    const playStopBtn = document.getElementById("playStopBtn");
57    const prevBtn = document.getElementById("prevBtn");
58    const nextBtn = document.getElementById("nextBtn");
59
60    function updatePlayStopButton() {
61        playStopBtn.innerHTML = audioElement.paused ? '<i class="fas fa-play"></i>' : '<i class="fas fa-pause"></i>';
62    }
63
64    function onAudioPlay() {
65        updatePlayStopButton();
66    }
67
68    function onAudioPause() {
69        updatePlayStopButton();
70    }
71
72    function onAudioWaiting() {
73        playStopBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i>'; // Using Font Awesome spinner here
74    }
75
76    function onAudioPlaying() {
77        updatePlayStopButton();
78    }
79
80    function onAudioCanPlay() {
81        updatePlayStopButton();
82    }
83
84    function onPrevBtnClick() {
85        console.log("Previous button clicked.");
86        audioElement.currentTime = Math.max(audioElement.currentTime - 10, 0);
87    }
88
89    function onNextBtnClick() {
90        console.log("Next button clicked.");
91        audioElement.load(); // Reload the source
92        audioElement.play(); // Play if it was playing before
93    }
94
95    function togglePlayStop() {
96        if (audioElement.paused) {
97            audioElement.play();
98        } else {
99            audioElement.pause();
100        }
101    }
102
103    // Attach event listeners
104    audioElement.addEventListener('play', onAudioPlay);
105    audioElement.addEventListener('pause', onAudioPause);
106    audioElement.addEventListener('waiting', onAudioWaiting);
107    audioElement.addEventListener('playing', onAudioPlaying);
108    audioElement.addEventListener('canplay', onAudioCanPlay);
109    
110    prevBtn.addEventListener('click', onPrevBtnClick);
111    nextBtn.addEventListener('click', onNextBtnClick);
112    playStopBtn.addEventListener('click', togglePlayStop);
113});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.