diff --git a/templates/soundboard.html b/templates/soundboard.html
index 4eded49..7a19831 100644
--- a/templates/soundboard.html
+++ b/templates/soundboard.html
@@ -19,7 +19,7 @@
@@ -49,6 +50,7 @@
const content = document.getElementById('sb-content');
let currentSB = null;
+ let autoTimer = null;
const statusBox = (msg, type='info') => {
console.log(msg);
};
@@ -117,6 +119,81 @@
if (!list.length) { container.innerHTML=''; randBtn.disabled=true; return; }
const items = list.map(s => `
${s.name || s.id || s.file}`).join('');
container.innerHTML = '
Zufallspool
max 2x pro Stunde je Datei.
';
+
+ renderAutoRandomControls();
+ }
+
+ function renderAutoRandomControls() {
+ const container = document.getElementById('sb-auto');
+ container.innerHTML = `
+
Automatik (Random)
+
+
+
+
+ Aus
+
+ `;
+
+ const start = document.getElementById('auto-start');
+ const stop = document.getElementById('auto-stop');
+ const status = document.getElementById('auto-status');
+
+ start.onclick = () => {
+ const imin = Math.max(1, parseInt(document.getElementById('auto-interval-min').value, 10) || 5);
+ const imax = Math.max(imin, parseInt(document.getElementById('auto-interval-max').value, 10) || 10);
+ const dmin = Math.max(0, parseInt(document.getElementById('auto-delay-min').value, 10) || 3);
+ const dmax = Math.max(dmin, parseInt(document.getElementById('auto-delay-max').value, 10) || 12);
+
+ const delayMs = randBetween(dmin, dmax) * 60 * 1000;
+ scheduleAuto(imin, imax, delayMs, status, start, stop);
+ };
+
+ stop.onclick = () => stopAuto(status, start, stop);
+ }
+
+ function randBetween(min, max) {
+ return min + Math.random() * (max - min);
+ }
+
+ function scheduleAuto(imin, imax, delayMs, status, startBtn, stopBtn) {
+ stopAuto(status, startBtn, stopBtn);
+ status.textContent = `Geplant in ${(delayMs/60000).toFixed(1)} min`;
+ startBtn.disabled = true;
+ stopBtn.disabled = false;
+ autoTimer = setTimeout(async function tick() {
+ await playRandom();
+ const nextMs = randBetween(imin, imax) * 60 * 1000;
+ status.textContent = `Nächster in ${(nextMs/60000).toFixed(1)} min`;
+ autoTimer = setTimeout(tick, nextMs);
+ }, delayMs);
+ }
+
+ function stopAuto(status, startBtn, stopBtn) {
+ if (autoTimer) {
+ clearTimeout(autoTimer);
+ autoTimer = null;
+ }
+ if (status) status.textContent = 'Aus';
+ if (startBtn) startBtn.disabled = false;
+ if (stopBtn) stopBtn.disabled = true;
}
async function playSound(sound) {
@@ -146,10 +223,14 @@
loadBtn.onclick = () => loadSoundboard(selectEl.value);
randBtn.onclick = async () => {
+ await playRandom();
+ };
+
+ async function playRandom() {
const res = await fetch('/api/soundboard/play_random', { method: 'POST' });
const data = await res.json();
if (!data.success) statusBox(data.message || 'Random fehlgeschlagen', 'warn');
- };
+ }
// Lautstärke
const vol = document.getElementById('sb-volume');