0
1
mirror of https://github.com/radio95-rnt/RadioPlayer.git synced 2026-02-26 21:53:54 +01:00
This commit is contained in:
2025-12-21 18:43:42 +01:00
parent 242d31b9c3
commit bfb2903aa6

View File

@@ -419,33 +419,35 @@
}); });
document.getElementById("clear-btn").addEventListener("click", () => {ws.send(JSON.stringify({action:"clear_toplay"}))}); document.getElementById("clear-btn").addEventListener("click", () => {ws.send(JSON.stringify({action:"clear_toplay"}))});
document.getElementById("add-to-queue-btn").addEventListener("click", () => { function addSelectedFileToQueue() {
let fullPath = null; let fullPath = null;
// Priority 1: Check for a selected file in the subdirectory list // Priority 1: selected subdirectory file
if (selectedSubFile && selectedDir) { if (selectedSubFile && selectedDir) {
fullPath = subbasePath.replace(/\/$/, '') + '/' + selectedSubFile; fullPath = subbasePath.replace(/\/$/, '') + '/' + selectedSubFile;
Array.from(document.getElementById("subdir-box").children).forEach(c => c.classList.remove("selected")); Array.from(document.getElementById("subdir-box").children).forEach(c => c.classList.remove("selected"));
selectedSubFile = null; selectedSubFile = null;
} else { }
// Priority 2: Check for a selected file in the main directory list // Priority 2: selected main directory file
else {
const dirEls = document.getElementById("dirs-box").children; const dirEls = document.getElementById("dirs-box").children;
const selectedItem = Array.from(dirEls).find(el => el.classList.contains("selected")); const selectedItem = Array.from(dirEls).find(el => el.classList.contains("selected"));
if (selectedItem) { if (selectedItem && selectedItem.dataset.type === "file") {
const name = selectedItem.textContent; fullPath = basePath.replace(/\/$/, '') + '/' + selectedItem.textContent;
// A simple check to see if the selected item is a file Array.from(dirEls).forEach(c => c.classList.remove("selected"));
if (selectedItem.dataset.type === "file") { selectedDir = null;
fullPath = basePath.replace(/\/$/, '') + '/' + name;
Array.from(dirEls).forEach(c => c.classList.remove("selected"));
selectedDir = null;
}
} }
} }
if (fullPath) ws.send(JSON.stringify({action:"add_to_toplay", songs: [fullPath]})) if (fullPath && ws && ws.readyState === WebSocket.OPEN) {
else alert("Please select a file to add."); ws.send(JSON.stringify({ action:"add_to_toplay", songs:[fullPath] }));
}); return true;
}
return false;
}
document.getElementById("add-to-queue-btn").addEventListener("click", addSelectedFileToQueue);
function updateControls() { function updateControls() {
document.getElementById("readd-btn").disabled = document.getElementById("readd-btn").disabled =
@@ -458,6 +460,10 @@
document.addEventListener("keydown", e => { document.addEventListener("keydown", e => {
if (e.target.tagName === "INPUT") return; if (e.target.tagName === "INPUT") return;
if (e.key === "Enter") {
const added = addSelectedFileToQueue();
if (added) e.preventDefault();
}
if (e.key === "s") ws.send(JSON.stringify({action:"skip"})); if (e.key === "s") ws.send(JSON.stringify({action:"skip"}));
if (e.key === "n") ws.send(JSON.stringify({action:"skip_next"})); if (e.key === "n") ws.send(JSON.stringify({action:"skip_next"}));
if (e.key === "j") ws.send(JSON.stringify({action:"jingle"})); if (e.key === "j") ws.send(JSON.stringify({action:"jingle"}));