-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
178 lines (159 loc) · 8.13 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
169
170
171
172
173
174
175
176
177
178
/* Light/Dark mode Toggle */
const btnTheme = document.querySelector('.btnTheme');
btnTheme.addEventListener("click", function(){
let body = document.getElementById("body");
let currentClass = body.className;
body.className = currentClass == "darkMode" ? "lightMode" : "darkMode";
if (currentClass == "lightMode"){
document.querySelector('.meteo').classList.add('fa-sun');
document.querySelector('.meteo').classList.remove('fa-moon');
let textmode = document.querySelector(".mode").innerHTML;
document.querySelector('.mode').innerHTML = textmode.replace("DARK", "LIGHT");
}else{
document.querySelector('.meteo').classList.add('fa-moon');
document.querySelector('.meteo').classList.remove('fa-sun');
let textmode = document.querySelector(".mode").innerHTML;
document.querySelector('.mode').innerHTML = textmode.replace("LIGHT", "DARK");
}
})
/* API GitHub */
const APIKEY = "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";
let apiCall = function(userName){
let url = `https://api.github.com/users/${userName}`;
fetch(url)
.then((response) =>
response.json().then((data) => {
/* backup api */
/* data = {
"login": "octocat",
"id": 583231,
"node_id": "MDQ6VXNlcjU4MzIzMQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/583231?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false,
"name": "The Octocat",
"company": "@github",
"blog": "https://github.blog",
"location": "San Francisco",
"email": null,
"hireable": null,
"bio": null,
"twitter_username": null,
"public_repos": 8,
"public_gists": 8,
"followers": 4721,
"following": 9,
"created_at": "2011-01-25T18:44:36Z",
"updated_at": "2022-01-24T15:08:43Z"
} */
/* msg error */
if(data.message){
document.querySelector('.error').style.visibility= "visible";
}else{
document.querySelector('.error').style.visibility= "hidden";
/* API: image */
let logo = document.querySelector(".avatar");
let src = logo.getAttribute("src");
src = data.avatar_url;
logo.setAttribute("src", src);
/* API: name + login */
if(data.name == null){
document.querySelector(".name").innerHTML = data.login;
}else{
document.querySelector(".name").innerHTML = data.name;
}
document.querySelector(".login").innerHTML = "@" + (data.login);
/* API: date de création */
let date = new Date(data.created_at);
const month = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
document.querySelector(".date").innerHTML = "Joined " + date.getDate() +" "+ month[date.getMonth()] +" "+ date.getFullYear();
/* API: bio */
if(data.bio == null){
document.querySelector(".profil").innerHTML = "This profile has no bio";
}else{
document.querySelector(".profil").innerHTML = data.bio;
}
/* API: stats */
document.querySelector(".repos").innerHTML = data.public_repos;
document.querySelector(".followers").innerHTML = data.followers;
document.querySelector(".following").innerHTML = data.following;
/* API: location */
if(data.location == null){
document.querySelector(".location").innerHTML = "Not available";
document.querySelector(".location").style.color = "rgb(75, 106, 155, 60%)";
document.querySelector(".fa-map-marker-alt").style.color = "rgb(75, 106, 155, 60%)";
}else{
document.querySelector(".location").innerHTML = data.location;
document.querySelector(".location").style.color = "#4B6A9B";
document.querySelector(".fa-map-marker-alt").style.color = "#4B6A9B";
}
/* API: twitter */
if(data.twitter_username == null){
document.querySelector(".twitter").innerHTML = "Not available";
document.querySelector(".twitter").style.color = "rgb(75, 106, 155, 60%)";
document.querySelector(".fa-twitter").style.color = "rgb(75, 106, 155, 60%)";
}else{
document.querySelector(".twitter").innerHTML = data.twitter_username;
document.querySelector(".twitter").style.color = "#4B6A9B";
document.querySelector(".fa-twitter").style.color = "#4B6A9B";
let twitter = document.querySelector(".twitter");
let href = twitter.getAttribute("href");
href = data.twitter_username;
twitter.setAttribute("href", "https://twitter.com/" + href);
}
/* API: company */
if(data.company == null){
document.querySelector(".company").innerHTML = "Not available";
document.querySelector(".company").style.color = "rgb(75, 106, 155, 60%)";
document.querySelector(".fa-building").style.color = "rgb(75, 106, 155, 60%)";
}else{
document.querySelector(".company").innerHTML = (data.company).substring(1);
document.querySelector(".company").style.color = "#4B6A9B";
document.querySelector(".fa-building").style.color = "#4B6A9B";
let company = document.querySelector(".company");
let href = company.getAttribute("href");
href = "https://" + data.company + ".com";
company.setAttribute("href", href);
}
/* API: blog */
if((data.blog == null) || (data.blog == "")){
document.querySelector(".blog").innerHTML = "Not available";
document.querySelector(".blog").style.color = "rgb(75, 106, 155, 60%)";
document.querySelector(".fa-link").style.color = "rgb(75, 106, 155, 60%)";
}else{
document.querySelector(".blog").innerHTML = data.blog;
document.querySelector(".blog").style.color = "#4B6A9B";
document.querySelector(".fa-link").style.color = "#4B6A9B";
let link = document.querySelector(".blog");
let href = link.getAttribute("href");
href = data.blog;
link.setAttribute("href", href);
}
}
})
)
}
/* btn search */
document.querySelector(".btnSearch").addEventListener('click', function(){
let user = document.querySelector('.searchBar').value;
apiCall(user)
})
document.querySelector(".searchBar").addEventListener("keydown", function(event){
if(event.key === "Enter"){
let user = document.querySelector('.searchBar').value;
apiCall(user)
}
})
apiCall("octocat");