From 3c31eb9b110281d06a216e5763305690fac67ea7 Mon Sep 17 00:00:00 2001 From: ronan-s1 Date: Thu, 8 Feb 2024 00:02:52 +0000 Subject: [PATCH] will work --- assets/scripts/scripts.js | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/assets/scripts/scripts.js b/assets/scripts/scripts.js index dceb986..1ce7cd2 100644 --- a/assets/scripts/scripts.js +++ b/assets/scripts/scripts.js @@ -16,36 +16,28 @@ document.addEventListener("DOMContentLoaded", function () { cursorElement.addEventListener("click", changeCursor); - const catGif = document.getElementById("catGif"); let gifIndex = 0; - let gifs = []; - - fetch("assets/img/cats/") - .then(response => response.text()) - .then(text => { - // Parse the HTML response to extract the GIF file names - const parser = new DOMParser(); - const htmlDocument = parser.parseFromString(text, "text/html"); - const links = Array.from(htmlDocument.querySelectorAll("a")); - - gifs = links - .map(link => link.href) - .filter(href => href.endsWith(".gif")); - - console.log(gifs) - console.log(gifs[gifIndex]) - catGif.src = gifs[gifIndex]; - }) - .catch(error => console.error("Error fetching data:", error)); - + const gifs = [ + "cat_1.gif", + "cat_2.gif", + "cat_3.gif", + "cat_4.gif", + "cat_5.gif", + "cat_6.gif", + "cat_7.gif", + "cat_8.gif", + "cat_9.gif" + ]; + + // Set the src of the catGif element + catGif.src = "https://foodindublin.com/assets/img/cats/" + gifs[gifIndex]; catGif.addEventListener("click", function() { gifIndex = (gifIndex + 1) % gifs.length; - catGif.src = gifs[gifIndex]; + catGif.src = "https://foodindublin.com/assets/img/cats/" + gifs[gifIndex]; }); - // Fetch data from the JSON file fetch("assets/data/data.json") .then(response => response.json())