- Failed to fetch the necessary data. Check to see if lainon.life is down.
-
-
-
- If it's not down then there's an issue with CORS, but you can probably it yourself! All you have to do is get an extension/add-on for your browser that enables CORS anywhere. If you're Chromium-based, check this one out. If you're on FireFox, I have no idea, maybe this one? Do keep in mind that enforcing CORS at all times could break some other sites you may frequent.
-
- Next FLEX: ${song.artist}
-
${song.title}
@@ -150,39 +143,45 @@ function parseData(radioData) {
${toMinSec(duration).join(":")}
`;
- e_songList.next.appendChild(e_songEntry);
-
+ e_songList.next.appendChild(e_songEntry);
- // Display the current song in the song list
- e_songList.current.innerHTML = `
+ // Display the current song in the song list
+ e_songList.current.innerHTML = `
`;
- // Fill in the previous songs
- for (const song of radioData.song_history) {
- const e_songEntry = document.createElement("div");
- e_songEntry.className = "song-entry";
+ // Fill in the previous songs
+ for (const song of radioData.song_history) {
+ const e_songEntry = document.createElement("div");
+ e_songEntry.className = "song-entry";
- e_songEntry.innerHTML = `
+ e_songEntry.innerHTML = `
${song.song.artist}
-
${song.song.title}
- ${toMinSec(song.duration).join(":")}
+ ${toMinSec(song.duration).join(
+ ":"
+ )}
`;
- e_songList.previous.appendChild(e_songEntry);
- }
+ e_songList.previous.appendChild(e_songEntry);
+ }
}
/**
@@ -192,10 +191,7 @@ function parseData(radioData) {
*/
function toMinSec(totalSeconds) {
- return [
- padZero(Math.floor(totalSeconds/60)),
- padZero(totalSeconds % 60)
- ];
+ return [padZero(Math.floor(totalSeconds / 60)), padZero(totalSeconds % 60)];
}
/**
@@ -205,9 +201,7 @@ function toMinSec(totalSeconds) {
*/
function padZero(integer) {
- return (integer < 10)
- ? "0" + integer
- : "" + integer
+ return integer < 10 ? "0" + integer : "" + integer;
}
/**
@@ -216,27 +210,45 @@ function padZero(integer) {
*/
function switchChannel(channelName) {
- console.log(e_audio.paused,isPlaying)
- if (e_audio.paused === false) {
- document.getElementById(channelName).classList.remove("active");
- e_audio.pause()
- isPlaying = false
- currentChannel = "cafe"
- e_audio.src = undefined
- return
- }
- // Remove active class from all DOM channel elements
- e_channels.forEach((el)=> el.classList.remove("active"));
+ e_player.classList.remove("paused");
+ // Remove active class from all DOM channel elements
+ e_channels.forEach((el) => el.classList.remove("active"));
- // Add it to the clicked one
- document.getElementById(channelName).classList.add("active");
+ // Add it to the clicked one
+ document.getElementById(channelName).classList.add("active");
- currentChannel = channelName;
- e_audio.src = `https://radio.scuf.ru/listen/scuf_fm/radio.mp3`;
- e_audio.play();
- fetchData();
+ currentChannel = channelName;
+ e_audio.src = `https://radio.scuf.ru/listen/scuf_fm/radio.mp3`;
+ e_audio.play();
+ fetchData();
- isPlaying = true;
+ isPlaying = true;
+}
+
+function pauseRadio() {
+ if (!isPlaying) {
+ return;
+ }
+
+ e_player.classList.add("paused");
+ progressStep = 0;
+ e_channels.forEach((el) => el.classList.remove("active"));
+ document.getElementById("pause").classList.add("active");
+ e_audio.pause();
+
+ isPlaying = false;
+}
+
+function toggleMute() {
+ if (e_audio.muted) {
+ document.getElementById("mute").classList.remove("active");
+ e_volumeBar.classList.remove("muted");
+ e_audio.muted = false;
+ } else {
+ document.getElementById("mute").classList.add("active");
+ e_volumeBar.classList.add("muted");
+ e_audio.muted = true;
+ }
}
// Change the volume
@@ -244,57 +256,48 @@ function switchChannel(channelName) {
let volumeUpdate; // Interval container
function setVolume(mouseEvent) {
- // If anything other than LMB is pressed, return early
- if (mouseEvent.buttons != 1) return;
+ // If anything other than LMB is pressed, return early
+ if (mouseEvent.buttons != 1) return;
- // Horizontal coordinate of the click
- const clickPosition = mouseEvent.offsetX;
+ // Horizontal coordinate of the click
+ const clickPosition = mouseEvent.offsetX;
- // Calculate new bar position and volume
- let volumeBarWidth = (100 / mouseEvent.target.clientWidth) * clickPosition;
- let audioVolume = (1 / mouseEvent.target.clientWidth) * clickPosition;
+ // Calculate new bar position and volume
+ let volumeBarWidth = (100 / mouseEvent.target.clientWidth) * clickPosition;
+ let audioVolume = (1 / mouseEvent.target.clientWidth) * clickPosition;
- // Resize the volume bar to the new width
- e_volumeBar.style.setProperty(
- "width",
- `${volumeBarWidth}%`
- );
+ // Resize the volume bar to the new width
+ e_volumeBar.style.setProperty("width", `${volumeBarWidth}%`);
- // Set the audio volume
- e_audio.volume = audioVolume;
+ // Set the audio volume
+ e_audio.volume = audioVolume;
}
e_player.onmousemove = setVolume;
e_player.onmousedown = setVolume;
-
// Refresh radio data when the tab is focused
-window.onfocus=()=> {
- if (isPlaying) fetchData();
-}
+window.onfocus = () => {
+ if (isPlaying) fetchData();
+};
// Update the progress bar every second
-const updateProgressBar = setInterval(()=> {
- // Current percentage
- const width = parseFloat(e_progressBar.style.width);
+const updateProgressBar = setInterval(() => {
+ // Current percentage
+ const width = parseFloat(e_progressBar.style.width);
- // Future percentage
- const futureWidth = width + progressStep;
+ // Future percentage
+ const futureWidth = width + progressStep;
- // If the future percentage doesn't exceed 100%
- // increment the progress bar.
+ // If the future percentage doesn't exceed 100%
+ // increment the progress bar.
- if (futureWidth < 100) {
- e_progressBar.style.setProperty(
- "width",
- futureWidth + "%"
- );
- }
+ if (futureWidth < 100) {
+ e_progressBar.style.setProperty("width", futureWidth + "%");
+ }
- // Otherwise, if it does exceed 100%, that means
- // the song has changed, so fetch the new data.
-
- else if (futureWidth >= 100)
- fetchData();
-}, 1000);
\ No newline at end of file
+ // Otherwise, if it does exceed 100%, that means
+ // the song has changed, so fetch the new data.
+ else if (futureWidth >= 100) fetchData();
+}, 1000);