-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
39 lines (34 loc) · 1.29 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
document.addEventListener("DOMContentLoaded", () => {
fetch("games.json")
.then((response) => response.json())
.then((data) => {
const linksSection = document.getElementById("links");
// Generate links dynamically
data.forEach((category) => {
const categoryTitle = document.createElement("h1");
categoryTitle.textContent = category.category;
linksSection.appendChild(categoryTitle);
category.games.forEach((game) => {
const link = document.createElement("a");
link.href = game.url;
const img = document.createElement("img");
img.className = "logo";
img.src = game.img;
img.title = game.title;
img.alt = `${game.title} logo`;
link.appendChild(img);
linksSection.appendChild(link);
});
});
// Add event listener for the randomizer button
document
.getElementById("randomGameButton")
.addEventListener("click", () => {
const allGames = data.flatMap((category) => category.games);
const randomGame =
allGames[Math.floor(Math.random() * allGames.length)];
window.location.href = randomGame.url;
});
})
.catch((error) => console.error("Error fetching JSON:", error));
});