fix Youtube

This commit is contained in:
nadja
2026-09-01 22:46:53 +02:00
parent 1162939720
commit bec7910eff
5 changed files with 193 additions and 25 deletions

62
app.js
View File

@@ -4,10 +4,57 @@
var TWITCH_CHANNEL = "duda_xd";
/* ------------------------------------------------------------------
* Twitch: Live-Player einbetten. Zeigt automatisch den aktuellen
* Stream, sobald du live bist. Die Domain wird dynamisch gesetzt,
* damit der Player ueberall funktioniert (auch lokal).
* Twitch ist ein iframe-Embed -> keine CORS-Probleme.
* YouTube: Liest die Datei videos.json, die auf dem Server von
* fetch_videos.py (einmal am Tag per Cron) mit den aktuellen
* Video-IDs deines Kanals aktualisiert wird.
*
* Dein API-Key ist dabei NIE im Browser - er bleibt komplett auf
* dem Server versteckt (siehe fetch_videos.py).
* ------------------------------------------------------------------ */
function loadYouTube() {
var grid = document.getElementById("yt-grid");
if (!grid) return;
fetch("videos.json", { cache: "no-cache" })
.then(function (r) {
if (!r.ok) throw new Error("HTTP " + r.status);
return r.json();
})
.then(function (ids) {
if (!Array.isArray(ids) || !ids.length) {
grid.innerHTML = '<div class="loading">Noch keine Videos vorhanden.</div>';
return;
}
renderYouTubeGrid(ids);
})
.catch(function () {
grid.innerHTML =
'<div class="loading error">Videos konnten nicht geladen werden.</div>';
});
}
function renderYouTubeGrid(videoIds) {
var grid = document.getElementById("yt-grid");
var html = "";
for (var i = 0; i < videoIds.length; i++) {
var id = String(videoIds[i]).trim();
if (!id) continue;
html +=
'<div class="video-card">' +
'<div class="video-wrapper">' +
'<iframe src="https://www.youtube.com/embed/' + id +
'" title="Duda17 Video" ' +
'frameborder="0" allow="accelerometer; autoplay; clipboard-write; ' +
'encrypted-media; gyroscope; picture-in-picture; web-share" ' +
'referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>' +
'</div>' +
'</div>';
}
grid.innerHTML = html || '<div class="loading">Keine Videos gefunden.</div>';
}
/* ------------------------------------------------------------------
* Twitch: Live-Player einbetten.
* ------------------------------------------------------------------ */
function loadTwitch() {
var wrap = document.getElementById("twitch-embed");
@@ -24,5 +71,8 @@
wrap.appendChild(iframe);
}
document.addEventListener("DOMContentLoaded", loadTwitch);
})();
document.addEventListener("DOMContentLoaded", function () {
loadYouTube();
loadTwitch();
});
})();