-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
75 lines (61 loc) · 2.27 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const url = "https://api.github.com/users/"
const section = document.querySelector("section")
const searchBox = document.querySelector("#searchUser").value
const form = document.querySelector("#myForm")
const getUser = async(username) => {
const response = await fetch(url + username)
const data = await response.json()
const card = `
<div class="card">
<div>
<img id="profile-pic" src="${data.avatar_url}" alt="user profile picture" class="avatar">
<h2>${data.name}</h2>
<p>${data.bio}</p>
</div>
<div class="userInfo">
<ul class="userInf">
<li>${data.followers} <span>Followers</span></li>
<li>${data.following} <span>Following</span></li>
<li>${data.public_repos} <span>Repos</span></li>
</ul>
<div>
<h3>Repositories</h3>
<div id="userRepos">
</div>
</div>
<div class="profile">
<button>
<a href="${data.html_url}" target="_blank">Go to prefile</a>
</button>
</div>
</div>
</div>
`
section.innerHTML = card;
getRepos(username)
}
const getRepos = async(username) => {
const repos = document.querySelector("#userRepos")
const response = await fetch(url + username + '/repos')
const data = await response.json()
data.forEach( item => {
const element = document.createElement("a")
const icon = document.createElement("img")
element.classList.add("repo")
element.href = item.html_url
element.innerText = `${item.name}`
element.target = "_blank"
icon.src = "./assets/folder.svg"
element.appendChild(icon)
repos.appendChild(element)
});
}
form.addEventListener("submit", function(e) {
e.preventDefault()
const inputValue = document.querySelector("#searchUser").value
const originalName = inputValue.split(' ').join('')
fetch(url + originalName)
.then(getUser(inputValue))
.catch(error => console.error(error))
})
// getUser("abouba03")