-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
64 lines (58 loc) · 1.87 KB
/
Copy pathapp.js
File metadata and controls
64 lines (58 loc) · 1.87 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
const set = new Set();
let mapsCounter = 0;
const MAX_MAPS = 3;
const getRaids = async (place = "nyc") => {
try {
const res = await fetch(`https://raw.githubusercontent.com/Pokedex100/Current-Raids/refs/heads/main/Data/${place}.json`);
if (!res) return;
const data = await res.json();
extractPokemonID(data, place);
} catch (e) {
console.error(e + " Map Down: " + place);
}
};
const getPokedexData = async () => {
const res = await fetch("https://raw.githubusercontent.com/Pokedex100/Current-Raids/refs/heads/main/Data/pokedexdata.json");
return await res.json();
};
getRaids("nyc");
getRaids("sgp");
getRaids("sydney");
const extractPokemonID = async (data, place) => {
for (const raid of data.raids) {
if (raid.pokemon_id) set.add(raid.pokemon_id);
}
mapsCounter++;
if (mapsCounter === MAX_MAPS) {
const pokemonIDs = [...set].sort((a, b) => a - b);
await getPokemonNames(pokemonIDs);
}
};
const getPokemonNames = async (pokemonIDs) => {
const pokedex = await getPokedexData();
const pokemonNames = [];
for (const id of pokemonIDs) {
const formattedID = id.toString().padStart(4, "0");
pokemonNames.push(pokedex[formattedID]);
}
generateUI(pokemonNames);
};
const generateUI = (names) => {
const container = document.createElement("div");
container.classList.add("container");
for (const name of names) {
const image = document.createElement("img");
image.src = `https://img.pokemondb.net/sprites/home/normal/${name}.png`;
image.alt = name;
const text = document.createElement("p");
const ripple = document.createElement("md-ripple");
text.textContent = name;
const card = document.createElement("div");
card.classList.add("card");
card.appendChild(image);
card.appendChild(text);
card.appendChild(ripple);
container.appendChild(card);
}
document.body.appendChild(container);
};