Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
66 lines (53 loc) · 1.98 KB
/
Copy pathscript.js
File metadata and controls
66 lines (53 loc) · 1.98 KB
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
const userNameInput=document.querySelector('#userName');
const showDetailsBtn=document.querySelector('#showDetails');
const profileInfoDiv=document.querySelector('#profileInfo');
const reposInfoDiv=document.querySelector('#reposInfo');
//fetch and show user info in a card
showDetailsBtn.addEventListener('click',async()=>{
const userName = userNameInput.value;
//fetch data of user from github server & resolving it because fetch will return a promise
const res=await fetch(`https://api.github.com/users/${userName}`)
const data=await res.json();
showProfile(data)
showReposInfo(userName);
});
function showProfile(data){
// console.log(data);
// show data in a card
profileInfoDiv.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>${data.followers} followers ${data.following} folloing</p>
<button>
<a href=${data.html_url}>Do Checkout Profile</a>
</button>
</div>
</div>
</div>`
};
// function to show repos of user
async function showReposInfo(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++) {
reposInfoDiv.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}>
Do checkout Project
</a>
</button>
</div>
</div>
</div>`
}
}