-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (52 loc) · 2.24 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
const inputValue = document.querySelector("#search");
const searchButton = document.querySelector(".searchButton");
const nameContainer = document.querySelector(".profile-name");
const followersContainer = document.querySelector(".profile-followers");
const reposContainer = document.querySelector(".profile-repos");
const followingContainer = document.querySelector(".profile-following");
const fetchContainer = document.querySelector(".profile-container");
const profilepicContainer = document.querySelector(".profile_pic");
var repoButton = document.querySelector(".profile_button")
const fetchUsers = async (user) => {
const api_call = await fetch(`https://api.github.com/users/${user}`);
const data = await api_call.json();
return {data: data};
}
const openUrl = () =>{
fetchUsers(inputValue.value).then((res) =>{
console.log(res);
window.open(`${res.data.html_url}`);}).catch(error =>{
alert("error");})
}
const showdata = () =>{
fetchUsers(inputValue.value).then((res) =>{
// console.log(res);
if (res.data.avatar_url == undefined){
alert("The Github User Doesnt Exist");
}
else{
nameContainer.innerHTML = `Name:<br> ${res.data.name}`;
followersContainer.innerHTML = `Followers:<br> ${res.data.followers}`;
followingContainer.innerHTML = `Following:<br> ${res.data.following}`;
reposContainer.innerHTML = `Repos:<br> ${res.data.public_repos}`;
profilepicContainer.innerHTML= `<img src = "${res.data.avatar_url}" alt = "Profile Picture" width = 100px>`
repoButton.classList.add("Button");
repoButton.innerHTML = 'Open Profile';
fetchContainer.classList.add("animate");
setTimeout(function() {
fetchContainer.classList.remove("animate");
}, 2000);
}
})}
searchButton.addEventListener("click", ()=>{
console.log(inputValue.value);
if (inputValue.value == ""){
alert("Please enter Github Username");
}
else{
showdata();
}
})
repoButton.addEventListener("click", ()=>{
openUrl();
})