Spaces:
Running
Running
Commit
·
64da8a6
1
Parent(s):
034b530
Update templates/index.html
Browse files- templates/index.html +43 -128
templates/index.html
CHANGED
@@ -266,139 +266,54 @@
|
|
266 |
<script>
|
267 |
|
268 |
// init
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
}
|
290 |
-
controller = new AbortController();
|
291 |
-
const signal = controller.signal;
|
292 |
-
|
293 |
-
try {
|
294 |
-
const response = await fetch(newUrl, { method: 'HEAD' , signal: signal});
|
295 |
-
if (!response.ok) {
|
296 |
-
console.error(`Fetch failed with status: ${response.status}`);
|
297 |
-
|
298 |
-
const urlParams = new URLSearchParams(window.location.search);
|
299 |
-
if (urlParams.get('id')) {
|
300 |
-
feed.style.width = "80px";
|
301 |
-
feed.style.height = "50px";
|
302 |
-
feed.src = loadingGif;
|
303 |
-
feed.style.opacity = "0.15";
|
304 |
-
countryElement.textContent = "couldn't connect.";
|
305 |
-
} else if (firstLoad) {
|
306 |
-
window.location.href = "?new=true";
|
307 |
-
} else {
|
308 |
-
console.log("Trying again");
|
309 |
-
setTimeout(refreshImage, 250);
|
310 |
-
}
|
311 |
-
return;
|
312 |
-
}
|
313 |
-
|
314 |
-
const contentType = response.headers.get('Content-Type');
|
315 |
-
if (response.ok) {
|
316 |
-
if (/image\/jpe?g/.test(contentType)) {
|
317 |
-
feed.src = newUrl + '?t=' + new Date().getTime();
|
318 |
-
isJpeg = true;
|
319 |
-
} else {
|
320 |
-
feed.src = newUrl;
|
321 |
-
isJpeg = false;
|
322 |
-
}
|
323 |
-
}
|
324 |
-
|
325 |
-
} catch (error) {
|
326 |
-
console.error('Fetch failed:', error);
|
327 |
-
|
328 |
-
}
|
329 |
-
}
|
330 |
-
});
|
331 |
-
|
332 |
-
async function init() {
|
333 |
-
feed.style.width = "80px";
|
334 |
-
feed.style.height = "50px";
|
335 |
-
feed.src = loadingGif;
|
336 |
-
feed.style.opacity = "0.15";
|
337 |
-
infoText.style.opacity = "0";
|
338 |
-
locationName.textContent = "{{ page_title|safe }}";
|
339 |
-
|
340 |
-
await refreshImage();
|
341 |
-
|
342 |
-
feed.onload = function() {
|
343 |
-
isLoading = false;
|
344 |
-
if (isJpeg) {
|
345 |
-
setTimeout(async () => {
|
346 |
-
await refreshImage();
|
347 |
-
}, 250);
|
348 |
-
}
|
349 |
-
|
350 |
-
if (firstLoad) {
|
351 |
-
countryElement.textContent = "connecting...";
|
352 |
-
infoDiv.style.opacity = "0";
|
353 |
-
}
|
354 |
-
firstLoad = false;
|
355 |
-
|
356 |
-
setTimeout(() => {
|
357 |
-
locationName.textContent = "{{ name|safe }}";
|
358 |
-
countryElement.textContent = "{{ country|safe }}";
|
359 |
-
feed.style.width = "100%";
|
360 |
-
feed.style.height = "70%";
|
361 |
-
feed.style.opacity = "1";
|
362 |
-
infoDiv.style.opacity = "1";
|
363 |
-
}, 100);
|
364 |
-
|
365 |
infoText.style.opacity = "1";
|
|
|
366 |
};
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
feed.style.opacity = "0.15";
|
378 |
-
countryElement.textContent = "couldn't connect.";
|
379 |
-
} else if (firstLoad) {
|
380 |
-
window.location.href = "?new=true";
|
381 |
-
} else {
|
382 |
-
firstLoad = false;
|
383 |
-
console.log("Trying again");
|
384 |
-
setTimeout(refreshImage, 500);
|
385 |
-
}
|
386 |
};
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
}
|
399 |
-
});
|
400 |
});
|
401 |
|
|
|
402 |
// Time count
|
403 |
document.addEventListener("DOMContentLoaded", function() {
|
404 |
const timezone = "{{ timezone }}";
|
|
|
266 |
<script>
|
267 |
|
268 |
// init
|
269 |
+
document.addEventListener("DOMContentLoaded", () => {
|
270 |
+
const feed = document.getElementById("feed");
|
271 |
+
const infoText = document.getElementById("info-text");
|
272 |
+
const country = document.getElementById("country");
|
273 |
+
const newUrl = "{{ url }}";
|
274 |
+
const loadingGif = "{{ url_for('static', filename='eye.gif') }}";
|
275 |
+
|
276 |
+
const setLoadingState = () => {
|
277 |
+
feed.style.width = "80px";
|
278 |
+
feed.style.height = "50px";
|
279 |
+
feed.src = loadingGif;
|
280 |
+
feed.style.opacity = "0.2";
|
281 |
+
infoText.style.opacity = "0";
|
282 |
+
};
|
283 |
+
|
284 |
+
const setLoadedState = () => {
|
285 |
+
feed.src = `${newUrl}?t=${new Date().getTime()}`;
|
286 |
+
feed.style.width = "100%";
|
287 |
+
feed.style.height = "70%";
|
288 |
+
feed.style.opacity = "1";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
infoText.style.opacity = "1";
|
290 |
+
country.textContent = "{{ country }}";
|
291 |
};
|
292 |
+
|
293 |
+
const refreshImage = () => {
|
294 |
+
let xhr = new XMLHttpRequest();
|
295 |
+
xhr.open('HEAD', `${newUrl}?t=${new Date().getTime()}`, true);
|
296 |
+
xhr.onreadystatechange = () => {
|
297 |
+
if (xhr.readyState === 4 && xhr.status === 200 && xhr.getResponseHeader('Content-Type') === 'image/jpeg') {
|
298 |
+
setLoadedState();
|
299 |
+
}
|
300 |
+
};
|
301 |
+
xhr.send();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
};
|
303 |
+
|
304 |
+
setLoadingState();
|
305 |
+
feed.onload = () => {
|
306 |
+
setLoadedState();
|
307 |
+
setTimeout(refreshImage, 1000);
|
308 |
+
};
|
309 |
+
feed.onerror = () => {
|
310 |
+
setLoadingState();
|
311 |
+
window.location.href = "?new=true";
|
312 |
+
};
|
313 |
+
feed.src = `${newUrl}?t=${new Date().getTime()}`;
|
|
|
|
|
314 |
});
|
315 |
|
316 |
+
|
317 |
// Time count
|
318 |
document.addEventListener("DOMContentLoaded", function() {
|
319 |
const timezone = "{{ timezone }}";
|