-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
168 lines (141 loc) · 4.58 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//Fetch the components
const lightButton=document.querySelector("[btnLight]");
const darkButton=document.querySelector("[btnDark]");
const searchForm=document.querySelector(".searchForm");
const searchBar=document.querySelector("[search]");
const searchBtn=document.querySelector("[searchBtn]");
const dp=document.querySelector("[displayPic]");
const user=document.querySelector("[userName]");
const ghLink=document.querySelector("[userLink]");
const joinDate=document.querySelector("[joinDate]");
const desc=document.querySelector("[desc]");
const repoData=document.querySelector("[repoData]");
const followData=document.querySelector("[followData]");
const followingData=document.querySelector("[followingData]");
const locn=document.querySelector("[locationData]");
const bd=document.querySelector("[bioData]");
const tLink=document.querySelector("[twitterLink]");
const cd=document.querySelector("[companyData]");
//Default variables
const initName="ash956901";
getUser(initName);
//eventListeners
searchForm.addEventListener("submit",(e)=>{
e.preventDefault();
let userName=searchBar.value;
if(userName==="")
return;
else
getUser(userName);
});
darkButton.addEventListener("click",()=>{
darkButton.classList.remove("active");
lightButton.classList.add("active");
let mainElement=document.querySelector(":root");
mainElement.style.cssText=`
--lm-bg: #141D2F;
--lm-bg-content:#1E2A47;
--lm-text: white;
--lm-text-alt: white;
--lm-shadow: 0px 16px 30px -10px rgba(70, 96, 187, 0.2);
--lm-shadow-inactive: 0px 16px 30px -10px rgba(0, 0, 0, 0.2);
--lm-icon-bg: brightness(1000%);
--btn: #0079ff;
--btn-hover: #60abff; `
//Links to White
searchBar.style.backgroundColor="#1E2A47";
tLink.style.color="white";
bd.style.color="white";
//Numbers to White
repoData.style.color="white";
followData.style.color="white";
followingData.style.color="white";
searchBar.style.color="white";
});
lightButton.addEventListener("click",()=>{
lightButton.classList.remove("active");
darkButton.classList.add("active");
let mainElement=document.querySelector(":root");
mainElement.style.cssText=`
--lm-bg: #f6f8ff;
--lm-bg-content: #fefefe;
--lm-text: #4b6a9b;
--lm-text-alt: #2b3442;
--lm-shadow: 0px 16px 30px -10px rgba(70, 96, 187, 0.2);
--lm-shadow-inactive: 0px 16px 30px -10px rgba(0, 0, 0, 0.2);
--lm-icon-bg: brightness(100%);
--btn: #0079ff;
--btn-hover: #60abff; `
//Links to White
searchBar.style.backgroundColor="white";
tLink.style.color="blue";
bd.style.color="blue";
//Numbers to White
repoData.style.color="black";
followData.style.color="black";
followingData.style.color="black";
searchBar.style.color="black";
});
//functions
async function getUser(username){
try{
const response=await fetch(`https://api.github.com/users/${username}`);
const data=await response.json();
renderData(data);
}
catch(e){
alert("No user found with the entered username");
repoData.innerText="";
followData.innerText="";
followingData.innerText="";
}
}
function renderData(data){
user.innerText=data?.name;
ghLink.innerText=`@`+`${data?.login}`;
ghLink.href=data?.html_url;
desc.innerText=data?.bio;
repoData.innerText=data?.public_repos;
followData.innerText=data?.followers;
followingData.innerText=data?.following;
locn.innerText=data?.location;
tLink.innerText=data?.twitter_username;
tLink.href=`https://www.twitter.com/${data?.twitter_username}`;
cd.innerText=data?.company;
bd.innerText=data?.blog;
bd.href=`${data?.blog}`;
dp.src=data?.avatar_url;
//Not Available Management
if(tLink.innerText===""){
tLink.innerText=`Not Available`;
// tLink.href="";
}
if(cd.innerText===""){
cd.innerText=`Not Available`;
}
if(bd.innerText===""){
bd.innerText=`Not Available`;
// bd.href="";
}
if(locn.innerText===""){
locn.innerText=`Not Available`;
}
if(desc.innerText===""){
desc.innerText=`This profile has no bio`;
}
if(user.innerText===""){
user.innerText=`Name not available`;
}
//Date
let tempDate=data?.created_at.split("T");
let tempDate2=tempDate[0].split("-");
let month=tempDate2[1];
let mon=whichMonth(month);
let year=tempDate2[0];
let day=tempDate2[2];
joinDate.innerText=` ${day}`+` ${mon}`+` ${year}`;
}
function whichMonth(month){
let arr=["Jan","Feb","March","April","May","June","July","August","Sep","Oct","Nov","Dec"];
return arr[month-1];
}