BraydenMoore commited on
Commit
410d5af
1 Parent(s): 5bbd7e3

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +20 -9
templates/index.html CHANGED
@@ -169,16 +169,27 @@
169
  const feed = document.getElementById("feed");
170
  feed.src = "{{ url_for('static', filename='loading.gif') }}";
171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  const newUrl = "{{ url }}";
173
-
174
- const img = new Image();
175
- img.onload = function() {
176
- feed.src = this.src;
177
- };
178
- img.onerror = function() {
179
- feed.src = "{{ url_for('static', filename='error.png') }}"; // You can set an error image here
180
- };
181
- img.src = newUrl;
182
  });
183
  </script>
184
  </body>
 
169
  const feed = document.getElementById("feed");
170
  feed.src = "{{ url_for('static', filename='loading.gif') }}";
171
 
172
+ function setImageSource(url, isImage = false) {
173
+ const img = new Image();
174
+ img.onload = function() {
175
+ feed.src = this.src;
176
+ if (isImage) {
177
+ setTimeout(() => setImageSource(url.replace("COUNTER", Math.random()), true), 500);
178
+ }
179
+ };
180
+ img.onerror = function() {
181
+ feed.src = "{{ url_for('static', filename='error.png') }}";
182
+ };
183
+ img.src = url;
184
+ }
185
+
186
  const newUrl = "{{ url }}";
187
+
188
+ fetch(newUrl, { method: 'HEAD' })
189
+ .then(response => {
190
+ const isImage = response.headers.get('Content-Type').startsWith('image/');
191
+ setImageSource(newUrl.replace("COUNTER", Math.random()), isImage);
192
+ });
 
 
 
193
  });
194
  </script>
195
  </body>