Skip to content

Commit

Permalink
will work
Browse files Browse the repository at this point in the history
  • Loading branch information
ronan-s1 committed Feb 8, 2024
1 parent e0d0f1d commit 3c31eb9
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions assets/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 3c31eb9

Please sign in to comment.