Spaces:
Running
Running
Update index.html
Browse files- index.html +13 -11
index.html
CHANGED
|
@@ -282,16 +282,6 @@
|
|
| 282 |
});
|
| 283 |
}
|
| 284 |
|
| 285 |
-
function validateImageUrl(url) {
|
| 286 |
-
const proxyUrl = `https://cors-anywhere.herokuapp.com/${url}`;
|
| 287 |
-
return new Promise((resolve, reject) => {
|
| 288 |
-
const img = new Image();
|
| 289 |
-
img.onload = () => resolve(true);
|
| 290 |
-
img.onerror = () => reject(new Error('Failed to load image. Please check the URL or ensure it allows cross-origin requests.'));
|
| 291 |
-
img.src = proxyUrl;
|
| 292 |
-
});
|
| 293 |
-
}
|
| 294 |
-
|
| 295 |
async function addImageFromUrl() {
|
| 296 |
const urlInput = document.getElementById('urlInput');
|
| 297 |
const url = urlInput.value.trim();
|
|
@@ -302,14 +292,17 @@
|
|
| 302 |
}
|
| 303 |
|
| 304 |
try {
|
| 305 |
-
|
|
|
|
| 306 |
|
| 307 |
const addButton = document.querySelector('.url-button');
|
| 308 |
addButton.disabled = true;
|
| 309 |
addButton.textContent = 'Loading...';
|
| 310 |
|
|
|
|
| 311 |
await validateImageUrl(url);
|
| 312 |
|
|
|
|
| 313 |
addImage({
|
| 314 |
id: Date.now(),
|
| 315 |
url: url
|
|
@@ -326,6 +319,15 @@
|
|
| 326 |
}
|
| 327 |
}
|
| 328 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
function addImage(image) {
|
| 330 |
images.unshift(image);
|
| 331 |
renderGallery();
|
|
|
|
| 282 |
});
|
| 283 |
}
|
| 284 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
async function addImageFromUrl() {
|
| 286 |
const urlInput = document.getElementById('urlInput');
|
| 287 |
const url = urlInput.value.trim();
|
|
|
|
| 292 |
}
|
| 293 |
|
| 294 |
try {
|
| 295 |
+
// Validate the URL format
|
| 296 |
+
new URL(url);
|
| 297 |
|
| 298 |
const addButton = document.querySelector('.url-button');
|
| 299 |
addButton.disabled = true;
|
| 300 |
addButton.textContent = 'Loading...';
|
| 301 |
|
| 302 |
+
// Validate the image URL by loading it into an <img> element
|
| 303 |
await validateImageUrl(url);
|
| 304 |
|
| 305 |
+
// Add the image to the gallery
|
| 306 |
addImage({
|
| 307 |
id: Date.now(),
|
| 308 |
url: url
|
|
|
|
| 319 |
}
|
| 320 |
}
|
| 321 |
|
| 322 |
+
function validateImageUrl(url) {
|
| 323 |
+
return new Promise((resolve, reject) => {
|
| 324 |
+
const img = new Image();
|
| 325 |
+
img.onload = () => resolve(true);
|
| 326 |
+
img.onerror = () => reject(new Error('Failed to load image. Please check the URL.'));
|
| 327 |
+
img.src = url;
|
| 328 |
+
});
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
function addImage(image) {
|
| 332 |
images.unshift(image);
|
| 333 |
renderGallery();
|