-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
72 lines (62 loc) · 2.14 KB
/
script.js
File metadata and controls
72 lines (62 loc) · 2.14 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Load games from JSON
let allGames = [];
fetch('games.json')
.then(response => response.json())
.then(data => {
allGames = data.games;
displayGames(allGames);
})
.catch(error => console.error('Error loading games:', error));
// Display games
function displayGames(games) {
const gamesGrid = document.getElementById('gamesGrid');
gamesGrid.innerHTML = '';
if (games.length === 0) {
gamesGrid.innerHTML = '<p style="grid-column: 1/-1; text-align: center; color: white; padding: 40px;">No games found</p>';
return;
}
games.forEach(game => {
const gameCard = document.createElement('div');
gameCard.className = 'game-card';
gameCard.innerHTML = `
<div class="game-card-image">${game.emoji}</div>
<div class="game-card-info">
<h3>${game.title}</h3>
<p>${game.category}</p>
</div>
`;
gameCard.addEventListener('click', () => openGame(game));
gamesGrid.appendChild(gameCard);
});
}
// Open game in modal
function openGame(game) {
const modal = document.getElementById('gameModal');
const gameFrame = document.getElementById('gameFrame');
const gameTitle = document.getElementById('gameTitle');
gameTitle.textContent = game.title;
gameFrame.src = game.url;
modal.style.display = 'block';
}
// Close modal
const modal = document.getElementById('gameModal');
const closeBtn = document.querySelector('.close');
closeBtn.addEventListener('click', () => {
modal.style.display = 'none';
document.getElementById('gameFrame').src = '';
});
window.addEventListener('click', (event) => {
if (event.target === modal) {
modal.style.display = 'none';
document.getElementById('gameFrame').src = '';
}
});
// Search functionality
document.getElementById('searchInput').addEventListener('keyup', (e) => {
const searchTerm = e.target.value.toLowerCase();
const filtered = allGames.filter(game =>
game.title.toLowerCase().includes(searchTerm) ||
game.category.toLowerCase().includes(searchTerm)
);
displayGames(filtered);
});