Spaces:
Running
Running
Commit
·
0451e9f
1
Parent(s):
beb9fdd
Update templates/index.html
Browse files- templates/index.html +63 -39
templates/index.html
CHANGED
@@ -265,54 +265,78 @@
|
|
265 |
|
266 |
<script>
|
267 |
|
268 |
-
|
269 |
-
|
|
|
|
|
|
|
270 |
const feed = document.getElementById("feed");
|
|
|
|
|
|
|
|
|
|
|
271 |
const infoText = document.getElementById("info-text");
|
272 |
-
|
273 |
-
|
274 |
-
const
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
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',
|
296 |
-
xhr.onreadystatechange = ()
|
297 |
-
if (xhr.readyState === 4
|
298 |
-
|
299 |
-
|
300 |
-
|
|
|
|
|
301 |
}
|
302 |
};
|
303 |
xhr.send();
|
304 |
-
}
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
setTimeout(refreshImage, 1000);
|
|
|
310 |
};
|
311 |
-
|
312 |
-
|
313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
};
|
315 |
-
|
|
|
316 |
});
|
317 |
|
318 |
|
|
|
265 |
|
266 |
<script>
|
267 |
|
268 |
+
// Handle feed load and refresh
|
269 |
+
let loadingGif = "{{ url_for('static', filename='eye.gif') }}";
|
270 |
+
let currentFeed;
|
271 |
+
let firstLoad = true;
|
272 |
+
document.addEventListener("DOMContentLoaded", function() {
|
273 |
const feed = document.getElementById("feed");
|
274 |
+
feed.style.width = "80px";
|
275 |
+
feed.style.height = "50px";
|
276 |
+
feed.src = loadingGif;
|
277 |
+
feed.style.opacity = "0.2";
|
278 |
+
const infoDiv = document.getElementById("info");
|
279 |
const infoText = document.getElementById("info-text");
|
280 |
+
infoText.style.opacity = "0";
|
281 |
+
|
282 |
+
const locationName = document.getElementById('location-name');
|
283 |
+
locationName.textContent = "{{ page_title }}";
|
284 |
+
|
285 |
+
const newUrl = "{{ url|safe }}";
|
286 |
+
|
287 |
+
function refreshImage() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
let xhr = new XMLHttpRequest();
|
289 |
+
xhr.open('HEAD', newUrl, true);
|
290 |
+
xhr.onreadystatechange = function() {
|
291 |
+
if (xhr.readyState === 4) {
|
292 |
+
if (xhr.status === 200) {
|
293 |
+
if (xhr.getResponseHeader('Content-Type') === 'image/jpeg') {
|
294 |
+
img.src = newUrl;
|
295 |
+
}
|
296 |
+
}
|
297 |
}
|
298 |
};
|
299 |
xhr.send();
|
300 |
+
}
|
301 |
+
|
302 |
+
const img = new Image();
|
303 |
+
img.onload = function() {
|
304 |
+
if (firstLoad) {
|
305 |
+
infoDiv.style.opacity = "0";
|
306 |
+
}
|
307 |
+
firstLoad = false;
|
308 |
+
old = newUrl;
|
309 |
+
setTimeout(() => {
|
310 |
+
feed.src = this.src;
|
311 |
+
locationName.textContent = "{{ name }}";
|
312 |
+
feed.style.width = "100%";
|
313 |
+
feed.style.height = "70%";
|
314 |
+
feed.style.opacity = "1";
|
315 |
+
infoDiv.style.opacity = "1";
|
316 |
+
}, 100);
|
317 |
+
const infoText = document.getElementById("info-text");
|
318 |
+
infoText.style.opacity = "1";
|
319 |
+
|
320 |
setTimeout(refreshImage, 1000);
|
321 |
+
country.textContent = "{{ country }}"
|
322 |
};
|
323 |
+
|
324 |
+
img.onerror = function() {
|
325 |
+
feed.style.width = "80px";
|
326 |
+
feed.style.height = "50px";
|
327 |
+
feed.src = loadingGif;
|
328 |
+
|
329 |
+
const urlParams = new URLSearchParams(window.location.search);
|
330 |
+
const countryElement = document.getElementById("country");
|
331 |
+
if (urlParams.get('new') === 'false') {
|
332 |
+
countryElement.textContent = "couldn't connect.";
|
333 |
+
}
|
334 |
+
else {
|
335 |
+
window.location.href = "?new=true";
|
336 |
+
}
|
337 |
};
|
338 |
+
|
339 |
+
img.src = newUrl;
|
340 |
});
|
341 |
|
342 |
|