-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
74 lines (62 loc) · 2.03 KB
/
app.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
const APIURL = "https://api.github.com/users/"; // Calling GitHub API
const main = document.querySelector("#main");
const searchBox = document.querySelector("#search")
const getUser = async(username) => {
const response = await fetch(APIURL + username);
const data = await response.json()
const card = `
<div class="card">
<div>
<img class="avatar" src="${data.avatar_url}" alt="Florin Pop">
</div>
<div class="user-info">
<h2>${data.name}</h2>
<p>${data.bio}</p>
<ul class="info">
<li>${data.followers}<strong>Followers</strong></li>
<li>${data.following}<strong>Following</strong></li>
<li>${data.public_repos}<strong>Repos</strong></li>
</ul>
<div id="repos">
</div>
</div>
</div>
`
main.innerHTML = card;
getRepos(username)
}
// init call
getUser("aarvi18") // Change this name for default GitHub Users!!
const getRepos = async(username) => {
const repos = document.querySelector("#repos")
const response = await fetch(APIURL + username + "/repos")
const data = await response.json();
data.forEach(
(item) => {
const elem = document.createElement("a")
elem.classList.add("repo")
elem.href = item.html_url
elem.innerText = item.name
elem.target = "_blank"
repos.appendChild(elem)
}
)
}
const formSubmit = () => {
if (searchBox.value != "") {
getUser(searchBox.value);
searchBox.value = ""
}
return false;
}
searchBox.addEventListener(
"focusout",
function() {
formSubmit()
}
)
/**
* <a class="repo" href="#" target="_blank">Repo 1</a>
<a class="repo" href="#" target="_blank">Repo 2</a>
<a class="repo" href="#" target="_blank">Repo 3</a>
*/