-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
44 lines (41 loc) · 1.35 KB
/
script.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
const output = document.querySelector("#output");
const userName = document.querySelector("#username");
const checkBtn = document.querySelector("#check-btn");
const avatar = document.querySelector("#avatar");
const repoHeading = document.querySelector("#repo-heading");
avatar.style.display = "none";
repoHeading.style.display = "none";
var url = "https://api.github.com/users/";
function getInfo() {
let x = userName.value;
let urlx = url + x;
output.innerHTML = " ";
fetch(urlx)
.then((res) => {
if (res.status == 200) {
return res.json();
} else {
avatar.style.display = "none";
avatar.src = "";
repoHeading.style.display = "none";
output.innerHTML = `<h2>Invalid UserName</h2>`;
}
})
.then((data) => {
avatar.style.display = "block";
avatar.src = data.avatar_url;
fetch(data.repos_url)
.then((res) => res.json())
.then((data) => {
repoHeading.style.display = "block";
for (let i = 0; i < data.length; i++) {
let reposURL = data[i].homepage;
let reposName = data[i].name;
if (reposURL && reposName !== "") {
output.innerHTML += `<li><a href="${reposURL}" target="_blank">${reposName}</a></li></ol>`;
}
}
});
});
}
checkBtn.addEventListener("click", getInfo);