queue/templates/index.html
2025-01-18 21:36:13 +02:00

155 lines
5.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head> <link rel="icon" type="image/x-icon" href="https://prigoana.com/favicon.png">
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Spotify Queue Manager</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 0;
padding: 20px;
}
form {
width: 100%;
}
input[type="text"] {
width: 80%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 5px;
}
.loading-spinner {
display: none;
text-align: center;
padding: 10px;
font-size: 16px;
color: #555;
}
.loading-spinner.active {
display: block;
}
/* Styling for the iframe to stretch to bottom and hide scrollbar */
iframe {
width: 100%;
height: calc(100vh); /* Adjusted to leave space for other content */
border: none;
overflow: hidden; /* Hide the scrollbar */
transition: height 0.3s ease-in-out;
}
/* Optional: Smooth fade on iframe content changes */
iframe.content {
transition: opacity 0.5s ease-in-out;
opacity: 1;
}
</style>
</head>
<body>
<h1>Queue</h1>
<form id="addSongForm" onsubmit="addSong(event)">
<input type="text" id="songInput" name="song_name" placeholder="Add song or artist" required>
<button style="width: 10%;" class="contrast" type="submit">Add</button>
</form>
<div class="message" id="message"></div>
<!-- Now Playing Widget -->
<p>Now Playing:</p>
<div class="now-playing" id="nowPlaying">
<div id="nowPlayingInfo">
</div>
</div>
<iframe id="queueTable" src="/queue_table" scrolling="no" seamless="seamless"></iframe>
<script>
// Function to handle song addition via GET request
async function addSong(event) {
event.preventDefault(); // Prevent the form from submitting normally
const songInput = document.getElementById("songInput");
const messageDiv = document.getElementById("message");
const songName = encodeURIComponent(songInput.value);
// Clear message and disable input/button during request
messageDiv.textContent = "Adding song...";
songInput.disabled = true;
try {
// Send GET request to add song
const response = await fetch(`/add?song_name=${songName}`);
const data = await response.json();
// Update message based on the response
if (response.ok) {
messageDiv.textContent = data.message || "Song added successfully!";
messageDiv.className = "message success";
} else {
throw new Error(data.error || "Failed to add the song.");
}
} catch (error) {
messageDiv.textContent = error.message;
messageDiv.className = "message error";
} finally {
// Re-enable input and clear it
songInput.disabled = false;
songInput.value = "";
}
// Show loading spinner
const loadingSpinner = document.getElementById("loadingSpinner");
loadingSpinner.classList.add("active");
}
// Function to fetch "Now Playing" information
async function fetchNowPlaying() {
try {
const response = await fetch('https://lastplayed.prigoana.com/Labirint84/');
const data = await response.json();
const track = data.track;
if (track && track["@attr"] && track["@attr"].nowplaying === "true") {
const nowPlayingInfo = document.getElementById('nowPlayingInfo');
const nowPlayingImage = document.getElementById('nowPlayingImage');
nowPlayingInfo.innerHTML = `${track.name} by ${track.artist["#text"]}`;
nowPlayingImage.innerHTML = `<img src="${track.image[2]["#text"]}" alt="${track.name}">`;
}
} catch (error) {
console.error('Error fetching now playing:', error);
}
}
// Call fetchNowPlaying on page load
fetchNowPlaying();
// Set an interval to fetch now playing every 3 seconds
setInterval(fetchNowPlaying, 3000);
// Function to update iframe content
async function updateIframeContent() {
try {
const iframe = document.getElementById("queueTable");
const response = await fetch('/queue_table');
const html = await response.text();
// Replace iframe content with smooth transition
iframe.srcdoc = html;
// Optionally: Apply smooth fade in for iframe content
iframe.classList.add('content');
} catch (error) {
console.error('Error updating iframe:', error);
}
}
// Update iframe content every 3 seconds
setInterval(updateIframeContent, 3000);
</script>
</body>
</html>