Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
68 lines (50 loc) · 1.69 KB
/
Copy pathscript.js
File metadata and controls
68 lines (50 loc) · 1.69 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
67
const APIURL = "https://api.github.com/users/";
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();
//add data from the json file to the card
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);
}
const getRepos = async(username) => {
const repos = document.querySelector("#repos");
const response = await fetch(APIURL + username + "/repos");
const data = await response.json();
// appending data into rightful elements of card
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);
}
return false;
}