| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>Image Index</title> |
| </head> |
| <body> |
| <h1>Image Index</h1> |
| <div id="image-container"></div> |
|
|
| <script> |
| |
| const imageContainer = document.getElementById("image-container"); |
| |
| |
| const imagePath = "images/"; |
| |
| |
| const imageExtensions = ["jpg", "jpeg", "png", "gif"]; |
| |
| |
| function displayImages() { |
| fetch(imagePath) |
| .then(response => response.text()) |
| .then(text => { |
| const parser = new DOMParser(); |
| const doc = parser.parseFromString(text, "text/html"); |
| const links = doc.querySelectorAll("a"); |
| |
| links.forEach(link => { |
| const href = link.getAttribute("href"); |
| const extension = href.split('.').pop().toLowerCase(); |
| |
| if (imageExtensions.includes(extension)) { |
| const img = document.createElement("img"); |
| img.src = imagePath + href; |
| img.alt = href; |
| imageContainer.appendChild(img); |
| } |
| }); |
| }); |
| } |
| |
| |
| displayImages(); |
| </script> |
| </body> |
| </html> |
|
|