Spaces:
Running
Running
Commit
·
a2c263a
1
Parent(s):
b85ac82
Update templates/index.html
Browse files- templates/index.html +36 -46
templates/index.html
CHANGED
@@ -263,70 +263,60 @@
|
|
263 |
<script>
|
264 |
|
265 |
// Handle feed load and refresh
|
266 |
-
let loadingGif = "{{ url_for('static', filename='eye.gif') }}";
|
267 |
-
let currentFeed;
|
268 |
-
let firstLoad = true;
|
269 |
document.addEventListener("DOMContentLoaded", function() {
|
270 |
const feed = document.getElementById("feed");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
feed.style.width = "80px";
|
272 |
feed.style.height = "50px";
|
273 |
feed.src = loadingGif;
|
274 |
feed.style.opacity = "0.15";
|
275 |
-
|
276 |
-
const infoDiv = document.getElementById("info");
|
277 |
-
const infoText = document.getElementById("info-text");
|
278 |
infoText.style.opacity = "0";
|
279 |
-
|
280 |
-
const locationName = document.getElementById('location-name');
|
281 |
-
const countryElement = document.getElementById("country");
|
282 |
locationName.textContent = "{{ page_title|safe }}";
|
283 |
-
|
284 |
-
const newUrl = decodeURIComponent("{{ url|safe }}");
|
285 |
-
|
286 |
async function refreshImage() {
|
287 |
-
const timestamp = new Date().getTime();
|
288 |
-
//const fetchUrl = `${newUrl}?t=${timestamp}`;
|
289 |
-
const fetchUrl = newUrl;
|
290 |
-
|
291 |
try {
|
292 |
-
const response = await fetch(
|
293 |
-
|
294 |
-
|
295 |
-
//img.src = `${newUrl}&t=${timestamp}`;
|
296 |
-
img.src = newUrl;
|
297 |
}
|
298 |
} catch (error) {
|
299 |
console.error('Fetch failed:', error);
|
300 |
}
|
301 |
}
|
302 |
-
|
303 |
const img = new Image();
|
304 |
-
img.onload = function() {
|
305 |
if (firstLoad) {
|
306 |
-
|
307 |
-
|
308 |
}
|
309 |
firstLoad = false;
|
|
|
310 |
setTimeout(() => {
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
infoDiv.style.opacity = "1";
|
318 |
}, 100);
|
319 |
-
|
320 |
-
const infoText = document.getElementById("info-text");
|
321 |
infoText.style.opacity = "1";
|
322 |
-
|
323 |
-
refreshImage();
|
324 |
};
|
325 |
-
|
326 |
img.onerror = function() {
|
327 |
console.error('Error loading image', this.src);
|
328 |
const urlParams = new URLSearchParams(window.location.search);
|
329 |
-
|
330 |
if (urlParams.get('id')) {
|
331 |
firstLoad = false;
|
332 |
feed.style.width = "80px";
|
@@ -334,20 +324,20 @@
|
|
334 |
feed.src = loadingGif;
|
335 |
feed.style.opacity = "0.15";
|
336 |
countryElement.textContent = "couldn't connect.";
|
337 |
-
}
|
338 |
-
else if (firstLoad) {
|
339 |
window.location.href = "?new=true";
|
340 |
-
}
|
341 |
-
else {
|
342 |
firstLoad = false;
|
343 |
-
console.log("Trying again")
|
344 |
setTimeout(refreshImage, 250);
|
345 |
-
}
|
346 |
-
|
347 |
-
|
|
|
348 |
console.log('Feed load success');
|
349 |
});
|
350 |
|
|
|
351 |
// Time count
|
352 |
document.addEventListener("DOMContentLoaded", function() {
|
353 |
const timezone = "{{ timezone }}";
|
|
|
263 |
<script>
|
264 |
|
265 |
// Handle feed load and refresh
|
|
|
|
|
|
|
266 |
document.addEventListener("DOMContentLoaded", function() {
|
267 |
const feed = document.getElementById("feed");
|
268 |
+
const infoDiv = document.getElementById("info");
|
269 |
+
const infoText = document.getElementById("info-text");
|
270 |
+
const locationName = document.getElementById("location-name");
|
271 |
+
const countryElement = document.getElementById("country");
|
272 |
+
let firstLoad = true;
|
273 |
+
|
274 |
+
const loadingGif = "{{ url_for('static', filename='eye.gif') }}";
|
275 |
+
const newUrl = decodeURIComponent("{{ url|safe }}");
|
276 |
+
|
277 |
feed.style.width = "80px";
|
278 |
feed.style.height = "50px";
|
279 |
feed.src = loadingGif;
|
280 |
feed.style.opacity = "0.15";
|
|
|
|
|
|
|
281 |
infoText.style.opacity = "0";
|
|
|
|
|
|
|
282 |
locationName.textContent = "{{ page_title|safe }}";
|
283 |
+
|
|
|
|
|
284 |
async function refreshImage() {
|
|
|
|
|
|
|
|
|
285 |
try {
|
286 |
+
const response = await fetch(newUrl, { method: 'HEAD' });
|
287 |
+
if (response.ok && /image\/jpe?g/.test(response.headers.get('Content-Type'))) {
|
288 |
+
feed.src = newUrl;
|
|
|
|
|
289 |
}
|
290 |
} catch (error) {
|
291 |
console.error('Fetch failed:', error);
|
292 |
}
|
293 |
}
|
294 |
+
|
295 |
const img = new Image();
|
296 |
+
img.onload = async function() {
|
297 |
if (firstLoad) {
|
298 |
+
countryElement.textContent = "connecting...";
|
299 |
+
infoDiv.style.opacity = "0";
|
300 |
}
|
301 |
firstLoad = false;
|
302 |
+
|
303 |
setTimeout(() => {
|
304 |
+
locationName.textContent = "{{ name|safe }}";
|
305 |
+
countryElement.textContent = "{{ country|safe }}";
|
306 |
+
feed.style.width = "100%";
|
307 |
+
feed.style.height = "70%";
|
308 |
+
feed.style.opacity = "1";
|
309 |
+
infoDiv.style.opacity = "1";
|
|
|
310 |
}, 100);
|
311 |
+
|
|
|
312 |
infoText.style.opacity = "1";
|
313 |
+
await refreshImage();
|
|
|
314 |
};
|
315 |
+
|
316 |
img.onerror = function() {
|
317 |
console.error('Error loading image', this.src);
|
318 |
const urlParams = new URLSearchParams(window.location.search);
|
319 |
+
|
320 |
if (urlParams.get('id')) {
|
321 |
firstLoad = false;
|
322 |
feed.style.width = "80px";
|
|
|
324 |
feed.src = loadingGif;
|
325 |
feed.style.opacity = "0.15";
|
326 |
countryElement.textContent = "couldn't connect.";
|
327 |
+
} else if (firstLoad) {
|
|
|
328 |
window.location.href = "?new=true";
|
329 |
+
} else {
|
|
|
330 |
firstLoad = false;
|
331 |
+
console.log("Trying again");
|
332 |
setTimeout(refreshImage, 250);
|
333 |
+
}
|
334 |
+
};
|
335 |
+
|
336 |
+
img.src = newUrl; // This will trigger img.onload when the image is loaded
|
337 |
console.log('Feed load success');
|
338 |
});
|
339 |
|
340 |
+
|
341 |
// Time count
|
342 |
document.addEventListener("DOMContentLoaded", function() {
|
343 |
const timezone = "{{ timezone }}";
|