-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
146 lines (106 loc) · 4.12 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const input = document.querySelector('.btn-div input');
const buton = document.querySelector('.btn-div button');
const contain = document.querySelector('.contain');
const followingLink = document.querySelector('.link1');
const following1 = document.querySelector('.following');
window.addEventListener('load',() => {
input.focus()
})
buton.addEventListener('click',getUser);
input.addEventListener('keypress', function (e) {
if (e.key === 'Enter'){
getUser()
}
});
async function getUser() {
try {
// const user = 'selman-s';
const user = input.value;
const url = await `https://api.github.com/users/${user}?client_id=3b925c08aab40ac38d05&client_secret=31be1b1285e20f238e8777adb3bc11907739a47b`;
const profileUser = await fetch(url);
const profile = await profileUser.json();
if(profile.documentation_url=='https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting'){
contain.innerHTML=`API rate limit exceeded for you <a href="https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting" target="_blank" >Click to documentation</a>`
}else{
writeUser(profile)
}
}
catch(err) {
alert('Error: ' + err.message)
}
}
function writeUser(profile){
const {login,avatar_url,html_url,public_repos,followers,following,name}=profile;
following1.innerHTML =''
contain.innerHTML = `<div class="main">
<div class="cart-top">
<div class="profile-img"><img src="${avatar_url}" alt=""></div>
</div>
<div class="cart-bottom">
<div class="desc">
<div class="desc-name">
<p class="login">${login}</p>
<p class="user-name">${name}</p>
</div>
<a class="link" href="${html_url}" target="_blank">View Profile</a>
<div class="fans">
<div class="fans-div">
<p class="quantity">${public_repos}</p>
<p class="fan">Public Repos</p>
</div>
<div class="fans-div">
<p class="quantity">${followers}</p>
<p class="fan">Followwers</p>
</div>
<div class="fans-div">
<p class="quantity">${following}</p>
<p class="fan">Followings</p>
</div>
</div>
</div>
</div>`
input.value ='';
input.focus();
getFollow()
}
async function getFollow() {
const user = document.querySelector('.login').textContent;
const url =await `https://api.github.com/users/${user}/following?client_id=3b925c08aab40ac38d05&client_secret=31be1b1285e20f238e8777adb3bc11907739a47b`;
console.log(url);
const profileUser = await fetch(url);
const profile = await profileUser.json();
profile.forEach(async (us)=>{
const url =await `https://api.github.com/users/${us.login}?client_id=3b925c08aab40ac38d05&client_secret=31be1b1285e20f238e8777adb3bc11907739a47b`;
const profileUser = await fetch(url);
const profile = await profileUser.json();
const {avatar_url,html_url,public_repos,followers,following,name}=profile;
console.log(profile);
following1.innerHTML +=`<div class="contain"><div class="main">
<div class="cart-top">
<div class="profile-img"><img src="${avatar_url}" alt=""></div>
</div>
<div class="cart-bottom">
<div class="desc">
<div class="desc-name">
<p class="user-name">${name}</p>
</div>
<a class="link" href="${html_url}" target="_blank">View Profile</a>
</div>
<div class="fans">
<div class="fans-div">
<p class="quantity">${public_repos}</p>
<p class="fan">Public Repos</p>
</div>
<div class="fans-div">
<p class="quantity">${followers}</p>
<p class="fan">Followwers</p>
</div>
<div class="fans-div">
<p class="quantity">${following}</p>
<p class="fan">Followings</p>
</div>
</div>
</div>
</div></div>`
});
}