-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
83 lines (70 loc) · 2.47 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const GitAPI = 'https://api.github.com/users/';
const form = document.querySelector('.form');
// console.log(form);
form.addEventListener('submit', (e) => {
e.preventDefault();
let inputUserName = form.querySelector('input').value;
console.log(inputUserName);
// input filed ko phir se blank karne ke liye
const input = document.querySelector('.search');
input.value = ''
getUser(inputUserName);
})
// console.log()
async function getUser(user) {
const resp = await fetch(GitAPI + user);
const respData = await resp.json(resp);
// console.log(respData);
fillInfo(respData);
}
function fillInfo(respdata) {
console.log(respdata);
const userImg = respdata.avatar_url;
// console.log(userImg);
const userName = respdata.login;
// console.log(userName);
const userBio = respdata.bio;
const userLocation = respdata.location;
const userMail = respdata.email;
console.log(userBio, userLocation, userMail);
const userFollower = respdata.followers;
const userFollowing = respdata.following;
const userRepo = respdata.public_repos;
console.log(userFollower, userFollowing, userRepo);
const userProfileLink = respdata.html_url;
const userRepos = `${respdata.html_url}?tab=repositories`
console.log(userProfileLink, userRepos);
if (userImg) {
document.querySelector('.userImg img').setAttribute('src', userImg);
}
if (userName) {
document.querySelector('.userInfo h1').innerText = userName;
}
if (userLocation) {
document.querySelector('.location').innerText = userLocation;
}
else {
document.querySelector('.location').innerText = 'Not mentioned';
}
if (userBio) {
document.querySelector('.bio').innerHTML = userBio;
} else {
document.querySelector('.bio').innerHTML = 'Not mentioned';
}
if (userMail) {
document.querySelector('.mail').innerHTML = userMail;
} else {
document.querySelector('.mail').innerHTML = 'Not mentioned';
}
if (userFollower) {
document.querySelector('.count-follower').innerText = userFollower;
}
if (userFollowing) {
document.querySelector('.count-following').innerText = userFollowing;
}
if (userRepo) {
document.querySelector('.count-repo').innerText = userRepo;
}
document.querySelector('.profileLink').setAttribute('href', userProfileLink);
document.querySelector('.repoLink').setAttribute('href', userRepos)
}