commit c038f723aec72873a5ef9f701bb0fedb06ef0916
parent 2157eabab3c42cd59bf1124473818aa0b5d29fac
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Tue, 10 Nov 2026 19:25:03 +0100
feat: add loading indicator
Diffstat:
3 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/assets/css/custom.css b/assets/css/custom.css
@@ -76,3 +76,34 @@ a[href^="https"]:where([href*="www.youtube.com"])::after {
#video_template {
display: none;
}
+
+#loading {
+ width: 15px;
+ height: 15px;
+ background-color: #fcd000;
+ border-radius: 50%;
+ position: absolute;
+ top: 23px;
+ left: 23px;
+ -webkit-animation: pulsate 1s ease-out;
+ -webkit-animation-iteration-count: infinite;
+ opacity: 0;
+}
+
+#loading.finished {
+ background-color: ##62bd19;
+ opacity: 1 !important;
+}
+
+#loading:not(.finished)::after {
+ content: "Loading...";
+}
+#loading.finished::after {
+ content: "Finished!";
+}
+
+@-webkit-keyframes pulsate {
+ 0% {-webkit-transform: scale(0.1, 0.1); opacity: 0.0;}
+ 50% {opacity: 1.0;}
+ 100% {-webkit-transform: scale(1.2, 1.2); opacity: 0.0;}
+}
diff --git a/assets/js/yt.js b/assets/js/yt.js
@@ -162,7 +162,6 @@ async function fetch_and_insert_yt(channel) {
} else {
document.querySelector("#channellist_" + channel).innerHTML = "<mark>ERROR</mark>";
document.querySelector("#channellist_" + channel).classList.add("error")
- return null; // exit immediately
}
// create and insert each video into the feed
@@ -188,3 +187,17 @@ async function fetch_and_insert_yt(channel) {
// Update loaded channels global
loaded_channels.push(channel);
}
+
+async function loading_indicator() {
+ while (true) {
+
+ var await_channels = document.querySelector("#loading").getAttribute("data");
+ if (await_channels == loaded_channels.sort) {
+ document.querySelector("#loading").classList.add("finished")
+ break;
+ }
+
+ // sleep
+ await new Promise(r => setTimeout(r, 2000));
+ }
+}
diff --git a/index.php b/index.php
@@ -146,6 +146,12 @@
</a>
</nav>
<h1>Videos</h1>
+ <stretch
+ id="loading"
+ onload="let loaded_channels = []; loading_indicator();"
+ data="<?php echo implode(",", $channels); ?>"
+ >
+ </stretch>
</header>
<form action="https://www.youtube.com/results" method="GET">
@@ -220,7 +226,6 @@
<!-- Fetch all videos via javascript and insert them into the feed -->
<script>
- let loaded_channels = [];
<?php
$i = 0;
foreach ($channels as $channel) {