-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
57 lines (54 loc) · 1.94 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
45
46
47
48
49
50
51
52
53
54
55
56
57
const userInput = document.getElementById("userName");
const getDetailsButton = document.getElementById("getDetails");
const profileInfo = document.getElementById("profileInfo");
const repoInfo = document.getElementById("repoInfo");
//!using async function to get the user details
getDetailsButton.addEventListener("click", async () => {
const userName = userInput.value;
//console.log(userName);
//!using the github api to fetch the data from server.
const res = await fetch(`https://api.github.com/users/${userName}`);
const data = await res.json();
//console.log(data);
getProfile(data);
getRepo(userName);
});
//!get profile function it is used to get the used details from the server.
function getProfile(data) {
console.log(data);
profileInfo.innerHTML = `<div class="card">
<div class="card-img">
<img src=${data.avatar_url} alt=${data.name}>
</div>
<div class="card-body">
<div class="card-title">${data.name}</div>
<div class="card-subHeading">${data.login}</div>
<div class="card-text">
<p>${data.bio}</p>
<p><i class="fa-solid fa-user-group"></i> ${data.followers} Followers ${data.following} Following </p>
<p><i class="fa-solid fa-location-dot"></i> ${data.location}</p>
<button>
<a href=${data.html_url} target="_blank">Visit Profile</a>
</button>
</div>
</div>
</div>`;
}
//!get repositories based on the username and passing another api to get that
async function getRepo(userName) {
const res = await fetch(`https://api.github.com/users/${userName}/repos`);
const projects = await res.json();
for (let i = 0; i < projects.length; i++) {
repoInfo.innerHTML += `<div class="card">
<div class="card-body">
<div class="card-title">${projects[i].name}</div>
<div class="card-subHeading">${projects[i].language}</div>
<div class="card-text">
<button>
<a href=${projects[i].html_url} target="_blank">Visit Projects</a>
</button>
</div>
</div>
</div>`;
}
}