-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (49 loc) · 2.16 KB
/
script.js
File metadata and controls
61 lines (49 loc) · 2.16 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
document.addEventListener('DOMContentLoaded', function() {
const gameListContainer = document.getElementById('game-list');
const searchInput = document.getElementById('search-input');
const categorySelect = document.getElementById('category-select');
let allGames = []; // Store all games loaded from JSON
// Load game data from JSON file
fetch('data.json')
.then(response => response.json())
.then(data => {
allGames = data.games; // Store all games
populateCategories(data.categories);
displayGames(allGames);
// Event listeners
searchInput.addEventListener('input', filterGames);
categorySelect.addEventListener('change', filterGames);
})
.catch(error => console.error('Error loading data:', error));
function populateCategories(categories) {
categories.forEach(category => {
const option = document.createElement('option');
option.value = category.toLowerCase();
option.textContent = category;
categorySelect.appendChild(option);
});
}
function filterGames() {
const searchTerm = searchInput.value.toLowerCase();
const selectedCategory = categorySelect.value;
let filteredGames = allGames;
if (selectedCategory !== 'all') {
filteredGames = filteredGames.filter(game => game.category.toLowerCase() === selectedCategory);
}
filteredGames = filteredGames.filter(game => game.name.toLowerCase().includes(searchTerm));
displayGames(filteredGames);
}
function displayGames(games) {
gameListContainer.innerHTML = ''; // Clear existing list
games.forEach(game => {
const gameItem = document.createElement('div');
gameItem.classList.add('game-item');
const gameLink = document.createElement('a');
gameLink.href = game.requestFileLink;
gameLink.textContent = game.name;
gameLink.target = "_blank"; // Open in new tab
gameItem.appendChild(gameLink);
gameListContainer.appendChild(gameItem);
});
}
});