pub / yt2html

Fetches Youtube content via RSS and provides a chronological timeline
git clone https://src.jayvii.de/pub/yt2html.git
Home | Log | Files | Exports | Refs | README | RSS

commit 16eb2d3e94dc723ea75853193d812b5e6f3db05f
parent 9dec78021a96516bce5dfeec6f616089f1c5f738
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Tue, 10 Nov 2026 18:56:39 +0100

fix: update channel list properly

Diffstat:
Massets/css/custom.css | 4++++
Massets/js/yt.js | 10++++++++--
Mindex.php | 31++++++++++++++++---------------
3 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/assets/css/custom.css b/assets/css/custom.css @@ -72,3 +72,7 @@ a[href^="https"]:where([href*="www.youtube.com"])::after { .error { background-color: red; } + +#video_template { + display: none; +} diff --git a/assets/js/yt.js b/assets/js/yt.js @@ -149,13 +149,16 @@ function create_video_box(data) { } -async function fetch_and_insert_yt(channel) { +function fetch_and_insert_yt(channel) { // gather feed information from API endpoint const videos_raw = await fetch('/lib/fetch_feed.php?channel=' + channel); // parse gathered information var videos = await videos_raw.json(); + // Update Channel List Name + document.querySelector("#channellist_" + channel).innerText = videos[0]["author"]; + // create and insert each video into the feed for (let i=0; i < videos.length; i++) { @@ -170,9 +173,12 @@ async function fetch_and_insert_yt(channel) { // If a video has a smaller (earlier) timestamp, put the video BEFORE it if (vids[j].getAttribute("data") < vid.getAttribute("data")) { - vids[j].prepend(vid); + vids[j].before(vid); break; } } } + + // Update loaded channels global + loaded_channels.append(channel); } diff --git a/index.php b/index.php @@ -179,28 +179,27 @@ <div id="channels_list"> <?php /* Draw Input fields for each channel ID */ - for ($i = 0; $i < count($channels_list); $i++) { + $i = 0; + foreach ($channels as $channel) { ?> <label for="channel_<?php echo $i; ?>"> - <?php - if ($channels_list[$i]["author"] != "") { - echo "<a href=\"/?channels=" . $channels_list[$i]["aid"] . - "\" target=\"_blank\">" . $channels_list[$i]["author"] . - "</a>"; - } else { - echo "<mark class=\"error\">Error</mark>"; - } - ?> + <a + id="channellist_<?php echo $channel; ?>" + href="/?channels=<?php echo $channel; ?>" + target="_blank" + > + </a> </label> <input name="channel_<?php echo $i; ?>" class="channels_input" type="text" - value="<?php echo $channels_list[$i]["aid"]; ?>" + value="<?php echo $channel; ?>" oninput="yt2html_update_channels_list();" > <?php - } + $i++; + } // foreach channel ?> <!-- Draw one empty input field for new entry by the user --> <label for="channel_<?php echo ($i); ?>"> @@ -221,11 +220,13 @@ <!-- Fetch all videos via javascript and insert them into the feed --> <script> + let loaded_channels = []; <?php + $i = 0; foreach ($channels as $channel) { - // echo "setTimeout(function() { fetch_and_insert_yt('" . - // $channel . "') }, 500);"; - echo "fetch_and_insert_yt('" . $channel . "');"; + echo "setTimeout(function() { fetch_and_insert_yt('" . + $channel . "') }, " . $i * 100 . ");"; + $i++; } ?> </script>