-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
66 lines (60 loc) · 2.19 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
const gBtn = document.querySelector('.btn');
const form = document.querySelector('.form');
const eror = document.querySelector('.eror');
const formBox = document.querySelector('.form-box');
const loader =document.querySelector('.loader');
const profile = document.querySelector('.profile');
gBtn.addEventListener('click' , ()=> {
const inpt = document.querySelector('#username');
formBox.style.display = 'none';
loader.style.display = 'block';
setTimeout(() => {
if(inpt.value == ''){
eror.style.display = 'block'
eror.textContent = '*Please enter your username.';
formBox.style.display = 'block';
loader.style.display = 'none';
} if(inpt.value[0] == '@'){
eror.style.display = 'block'
eror.textContent = '*Don\'t use @';
formBox.style.display = 'block';
loader.style.display = 'none';
} if(!(inpt.value =='') && !(inpt.value[0]=='@')){
let username = inpt.value;
github(username);
}
}, 1000);
})
function github(username){
let xhr = new XMLHttpRequest();
xhr.open('GET' , `https://api.github.com/users/${username}` , true);
xhr.onload = function(){
if(this.status === 200){
eror.style.display = 'none';
let jsn = JSON.parse(this.responseText);
let fName = jsn.name;
let pic = jsn.avatar_url;
let bio = jsn.bio;
let followers = jsn.followers;
let following = jsn.following;
let id = `@${jsn.login}`;
document.querySelector('#pic').src = pic;
document.querySelector('#fname').textContent = fName;
document.querySelector('.id').textContent = id;
document.querySelector('.fols').textContent = followers;
document.querySelector('.folg').textContent = following;
document.querySelector('#bio').textContent = bio;
const githubUrl = document.querySelector('#github-url');
githubUrl.href = 'https://github.com/'+jsn.login;
profile.style.display = 'flex'
form.style.display = 'none'
loader.style.display = 'none';
} else {
formBox.style.display = 'block';
loader.style.display = 'none';
eror.style.display = 'block';
eror.textContent = 'Username Not Found! try again.';
}
}
xhr.send();
}