fix Youtube

This commit is contained in:
nadja
2026-09-01 23:13:15 +02:00
parent bec7910eff
commit df3c972342
4 changed files with 43 additions and 43 deletions

64
app.js
View File

@@ -3,38 +3,18 @@
var TWITCH_CHANNEL = "duda_xd";
/* ------------------------------------------------------------------
* 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>';
});
}
/* Rendert die Video-IDs aus videos.js als iframes.
* Standard-iframe laut YouTube-Empfehlung. Bewusst OHNE
* referrerpolicy und OHNE ?si-Parameter: Dann sendet der Browser
* immer einen Referer (auch bei HTTP-Seite), den YouTube braucht,
* um den Embedder zu erkennen (sonst Fehler 152/153). */
function renderYouTubeGrid(videoIds) {
var grid = document.getElementById("yt-grid");
if (!grid) return;
if (!videoIds || !videoIds.length) {
grid.innerHTML = '<div class="loading">Noch keine Videos vorhanden.</div>';
return;
}
var html = "";
for (var i = 0; i < videoIds.length; i++) {
var id = String(videoIds[i]).trim();
@@ -42,17 +22,31 @@
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>' +
'<iframe width="560" height="315" ' +
'src="https://www.youtube.com/embed/' + id + '" ' +
'title="YouTube video player" ' +
'frameborder="0" ' +
'allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" ' +
'allowfullscreen></iframe>' +
'</div>' +
'</div>';
}
grid.innerHTML = html || '<div class="loading">Keine Videos gefunden.</div>';
}
/* ------------------------------------------------------------------
* YouTube: Liest die Video-IDs aus videos.js, 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 ids = (typeof DUDA17_VIDEOS !== "undefined") ? DUDA17_VIDEOS : [];
renderYouTubeGrid(ids);
}
/* ------------------------------------------------------------------
* Twitch: Live-Player einbetten.
* ------------------------------------------------------------------ */