-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (56 loc) · 1.95 KB
/
script.js
File metadata and controls
63 lines (56 loc) · 1.95 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
// https://codepen.io/jamesqquick/pen/XWJxBQv
const searchBar = document.getElementById("searchBar"); // Gets the reference to the search bar
const gameList = ['Dota 2', 'Battlefield 2042', 'League Of Legends', 'Valorant', 'World of Warcraft', 'CS-GO', 'Fortnite', 'World of Tanks'];
const charactersList = document.getElementById('charactersList');
const gameSearchBar = document.getElementById('searchBar');
let proPlayers = [];
const resizeBrowser = () => {
let x = document.getElementById("myTopnav");
if (x.className === "navbarlinks") {
x.className += " responsive";
} else {
x.className = "navbarlinks";
}
}
// keyUp -> anytime a key is pressed
searchBar.addEventListener('keyup', (e) => {
const searchString = e.target.value.toLowerCase();
const filteredGame = gameList.filter(gameName => {
return gameName.toLowerCase().includes(searchString);
});
});
gameSearchBar.addEventListener('keyup', (e) => {
const searchString = e.target.value.toLowerCase();
const filteredPlayers = proPlayers.filter((player) => {
return (
player.name.toLowerCase().includes(searchString) ||
player.steamid.toLowerCase().includes(searchString)
);
});
console.log(filteredPlayers);
displayPlayers(filteredPlayers);
});
const loadPlayers = async () => {
try {
const res = await fetch('https://api.opendota.com/api/proPlayers');
proPlayers = await res.json();
displayPlayers(proPlayers);
} catch (err) {
console.error(err);
}
};
const displayPlayers = (players) => {
const htmlString = players
.map((player) => {
return `
<li class="player">
<a target='_blank' href=${player.profileurl}><h2>${player.name}</h2></a>
<p>SteamID: ${player.steamid}</p>
<img src="${player.avatarfull}"></img>
</li>
`;
})
.join('');
playersList.innerHTML = htmlString;
};
loadPlayers();