-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
114 lines (93 loc) · 3.46 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const API_URL = "https://api.github.com/users/";
const SearchInput = document.querySelector("input");
const SearchBtn = document.getElementById("search_btn");
const ModeBtn = document.getElementById("mode_btn");
const Results = document.querySelector(".card_body")
currentUser()
async function currentUser(){
let currentUser = "reactanvar"
const res = await fetch(API_URL + currentUser);
const resData = await res.json();
console.log(resData)
const div =`
<div>
<img class="user_image" src="${resData.avatar_url}" alt="user profile image">
</div>
<div>
<h1 class="name">${resData.name}</h1>
<p class="username">@${resData.login}</p>
<span class="user_bio">${resData.bio}</span>
<div class="statistic_section">
<div class="followers">
Followers: <span>${resData.followers}</span>
</div>
<div class="following">
Followings: <span>${resData.following}</span>
</div>
<div class="repositories">
Repositories: <span>${resData.public_repos}</span>
</div>
</div>
<div class="others">
<div class="location">
<i class='bx bx-map-pin'></i><span>${resData.location}</span>
</div>
<div class="company">
<i class='bx bx-buildings'></i><span>${resData.company}</span>
</div>
<div class="link">
<i class='bx bx-link' ></i><span class="link"><a href="https://${resData.blog}" target="_blacnk" >${resData.blog}<a/></span>
</div>
</div>
</div>
`
Results.innerHTML =div;
}
async function getUser(){
const res = await fetch(API_URL + SearchInput.value.trim());
const resData = await res.json();
console.log(resData)
if(!resData.message){
const div =`
<div>
<img class="user_image" src="${resData.avatar_url}" alt="user profile image">
</div>
<div>
<h1 class="name">${resData.name}</h1>
<p class="username">@${resData.login}</p>
<span class="user_bio">${resData.bio}</span>
<div class="statistic_section">
<div class="followers">
Followers: <span>${resData.followers}</span>
</div>
<div class="following">
Followings: <span>${resData.following}</span>
</div>
<div class="repositories">
Repositories: <span>${resData.public_repos}</span>
</div>
</div>
<div class="others">
<div class="location">
<i class='bx bx-map-pin'></i><span>${resData.location}</span>
</div>
<div class="company">
<i class='bx bx-buildings'></i><span>${resData.company}</span>
</div>
<div class="link">
<i class='bx bx-link' ></i><span class="link"><a href="${resData.blog}" target="_blacnk" >${resData.blog}<a/></span>
</div>
</div>
</div>
`
Results.innerHTML =div;
}
}
SearchInput.addEventListener("keyup" , async function(e){
if(e.keyCode == 13 && SearchInput.value.trim() != ''){
getUser()
}
})
SearchBtn.addEventListener("click", function(){
getUser()
})