Last active
November 27, 2018 02:01
-
-
Save manobi/f4cb8cb3f085502987ede8dc41179899 to your computer and use it in GitHub Desktop.
pokedexscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var modal = document.getElementById('myModal'); | |
var btn = document.getElementById("myBtn"); | |
var span = document.getElementsByClassName("close")[0]; | |
btn.onclick = function () { | |
modal.style.display = "block"; | |
} | |
span.onclick = function () { | |
modal.style.display = "none"; | |
} | |
window.onclick = function (event) { | |
if (event.target == modal) { | |
modal.style.display = "none"; | |
} | |
} | |
var date_time = document.getElementById('date_captura').value = new Date().toISOString().slice(0, 18).replace('T', ' '); | |
function takeValue(){ | |
var pokemonName = document.getElementById('captura_pokemon').value; | |
var ipt_abilities = document.getElementById('ability'); | |
ipt_abilities.value = ''; | |
var P = new Pokedex.Pokedex({ protocol: 'https' , cache: false}); | |
P.getPokemonByName(pokemonName) | |
.then((res) => { | |
//return console.log(res.abilities[0].ability.name); | |
if(res.abilities && res.abilities.length){ | |
ipt_abilities.value = res.abilities.map((ability, i) => { | |
return ability.ability.name; | |
}).join(','); | |
} | |
}).catch(err => console.log('pokemon não encontrado')); | |
}; | |
document.querySelector('#captura_pokemon').addEventListener('keyup', () => { | |
takeValue(); | |
}); | |
function updateList(){ | |
fetch('/pokedex').then(res => res.json()).then((data) => { | |
for (var pokemon in data) { | |
const ul = document.getElementById('listPokemons') | |
const item = document.createElement('li') | |
item.textContent = pokemon.captura_pokemon | |
ul.appendChild(item) | |
} | |
}); | |
} | |
document.addEventListener("DOMContentLoaded", function (event) { | |
updateList(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment