-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
97 lines (88 loc) · 2.29 KB
/
index.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
let started=false;
let pagina='Dex';
function getAtrapados(){
return JSON.parse(localStorage.getItem('atrapados')||'{"Dex":[],"Shiny":[],"Unown":[]}');
}
let cantidadDePokemones=60;
// fetch('https://pokeapi.co/api/v2/pokemon/?limit=905')
fetch('https://pokeapi.co/api/v2/pokemon/?limit='+cantidadDePokemones)
.then(res=>res.json())
.then(res=>{
console.log(res.results);
let todos=res.results.map(pok=>{
pok.name=pok.name
.replace('-f',' ♀')
.replace('-m',' ♂');
return pok;
});
Alpine.store('pokemonesDex',todos);
Alpine.store('pokemonesShiny',todos);
Alpine.store('title','Dex');
Alpine.store('atrapados',getAtrapados())
fetch('https://pokeapi.co/api/v2/pokemon/201')
.then(res=>res.json())
.then(unowns=>{
let unown=[];
for(let uno of unowns.forms){
let letra=uno.name.split('-')[1];
let id='-'+letra;
let name=letra.toUpperCase();
switch(letra){
case 'a':
id='';
break;
case 'exclamation':
name='!';
break;
case 'question':
name='?';
break;
}
unown.push({id,name});
}
// console.log(unown,unowns);
Alpine.store('pokemonesUnown',unown);
if(!started){
Alpine.start();
started=true;
}
})
});
// Alpine.start();
function cambiarEstado(id,atrapado,coleccion){
let atrapados=getAtrapados();
if(atrapado){
atrapados[coleccion].push(id);
}else{
atrapados[coleccion].splice(atrapados[coleccion].indexOf(id),1);
}
Alpine.store('atrapados',atrapados);
localStorage.setItem('atrapados',JSON.stringify(atrapados));
}
page.configure({
window:window
,hashbang:true
})
function mostrarSeccion(id){
let viejo=document.querySelector('.not-hidden');
viejo.classList.remove('not-hidden');
document.getElementById(id).classList.add('not-hidden');
document.body.classList.remove('main');
}
page('/', ()=>{
mostrarSeccion('main');
document.body.classList.add('main');
})
page('/dex', ()=>{
pagina='Dex';
mostrarSeccion('dex');
})
page('/shiny', ()=>{
pagina='Shiny';
mostrarSeccion('shiny');
})
page('/unown', ()=>{
pagina='Unown';
mostrarSeccion('unown');
})
window.page=page;