-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (26 loc) · 969 Bytes
/
script.js
File metadata and controls
30 lines (26 loc) · 969 Bytes
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
document.addEventListener("DOMContentLoaded", () => {
const inputSearch = document.querySelector("#search-user");
searchUser(inputSearch.value);
inputSearch.addEventListener("input", () => {
searchUser(inputSearch.value)
})
})
const updateCardGithub = (data) => {
if (data) {
document.querySelector("#profile-image").src = data.avatar_url;
document.querySelector("#name").innerHTML = data.login;
document.querySelector("#bio").innerHTML = data.bio;
document.querySelector("#public-repos").innerHTML = data.public_repos;
document.querySelector("#followers").innerHTML = data.followers;
document.querySelector("#following").innerHTML = data.following;
document.querySelector("#url-github").href = data.html_url;
}
}
const searchUser = (username) => {
if (username) {
const url = `https://api.github.com/users/${username}`
fetch(url)
.then(res => res.json())
.then(data => updateCardGithub(data))
}
}