-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
190 lines (160 loc) · 6.23 KB
/
Copy pathscript.js
File metadata and controls
190 lines (160 loc) · 6.23 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
const root = document.documentElement.style;
const btnmode = document.querySelector("#btn-mode");
const modeText = document.querySelector("#mode-text");
const modeIcon = document.querySelector("#mode-icon")
let darkMode = false;
btnmode.addEventListener('click', () => {
if (darkMode == false)
activateDarkMode();
else
activateLightMode();
});
//SWITCH TO DARK MODE
function activateDarkMode() {
root.setProperty("--lm-bg", "#141D2F");
root.setProperty("--lm-bg-content", "#1E2A47");
root.setProperty("--lm-text", "white");
root.setProperty("--lm-text-alt", "white");
root.setProperty("--lm-shadow-xl", "rgba(70,88,109,0.15)");
modeText.textContent = "LIGHT";
modeIcon.src = "assets/sun-icon.svg";
// root.setProperty("--lm-icon-bg", "brightness(1000%)");
darkMode = true;
// console.log("darkmode changed to " + darkMode);
localStorage.setItem("dark-mode", true);
}
//SWITCH TO LIGHT MODE
function activateLightMode() {
root.setProperty("--lm-bg", "#F6F8FF");
root.setProperty("--lm-bg-content", "#FEFEFE");
root.setProperty("--lm-text", "#4B6A9B");
root.setProperty("--lm-text-alt", "#2B3442");
root.setProperty("--lm-shadow-xl", "rgba(70, 88, 109, 0.25)");
modeText.textContent = "DARK";
modeIcon.src = "assets/moon-icon.svg";
// root.setProperty("--lm-icon-bg", "brightness(100%)");
darkMode = false;
localStorage.setItem("dark-mode", false);
}
const btnSubmit = document.querySelector("#submit");
const input = document.querySelector("#input");
const url = "https://api.github.com/users/";
const noresults = document.querySelector("#no-results")
btnSubmit.addEventListener('click', () => {
if (input.value !== '')
getUserData(url + input.value);
else {
noresults.style.display = "block";
noresults.textContent = "Please Enter Username";
}
});
input.addEventListener('input', () => {
noresults.style.display = 'none';
});
input.addEventListener('click', () => {
noresults.style.display = 'none';
});
input.addEventListener('keydown', (event) => {
if (event.key == "Enter") {
if (input.value !== "")
getUserData(url + input.value);
}
})
// API CALL
async function getUserData(gitUrl) {
try {
const response = await fetch(gitUrl);
const data = await response.json();
console.log(data);
updateProfile(data);
}
catch (err) {
throw err;
}
}
// VARIABLES
const avatar = document.querySelector("#avatar");
const userName = document.querySelector("#name");
const userId = document.querySelector("#userid");
const date = document.querySelector("#date");
const bio = document.querySelector("#bio");
const repos = document.querySelector("#repos");
const followers = document.querySelector("#followers");
const following = document.querySelector("#following");
const userLocation = document.querySelector("#location");
const page = document.querySelector("#page");
const twitter = document.querySelector("#twitter");
const company = document.querySelector("#company");
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
const searchbar = document.querySelector(".searchbar-container");
const profilecontainer = document.querySelector(".profile-container");
// RENDER
function updateProfile(data) {
if (data.message !== 'Not Found') {
noresults.style.display = 'none';
// CHECK FOR NULL VALUES
function checkNull(val1, val2) {
if (val1 == "" || val1 == null) {
val2.style.opacity = 0.5;
val2.previousElementSibling.style.opacity = 0.5;
return true;
}
else{
val2.style.opacity = 1;
val2.previousElementSibling.style.opacity = 1;
return false;
}
}
avatar.src = `${data.avatar_url}`;
userName.textContent = `${data.name}`;
userId.textContent = `@${data.login}`;
userId.href = `${data.html_url}`;
dateSegments = data.created_at.split('T').shift().split('-');
// console.log(dateSegments);
date.textContent = `Joined ${dateSegments[2]} ${months[dateSegments[1] - 1]} ${dateSegments[0]}`;
bio.textContent = data.bio == null ? "This profile has no bio" : `${data.bio}`;
repos.textContent = `${data.public_repos}`;
followers.textContent = `${data.followers}`;
following.textContent = `${data.following}`;
userLocation.textContent = checkNull(data.location, userLocation) ? "Not Available" : `${data.location}`;
page.textContent = checkNull(data.blog, page) ? "Not Available" : data.blog;
page.href = checkNull(data.blog, page) ? "" : data.blog;
page.style.textDecoration = "none";
twitter.textContent = checkNull(data.twitter_username, twitter) ? "Not Available" : data.twitter_username;
twitter.href = checkNull(data.twitter_username, twitter) ? "" : `https://twitter.com/${data.twitter_username}`;
twitter.style.textDecoration = "none";
company.textContent = checkNull(data.company, company) ? "Not Available" : data.company;
if (data.blog == "") {
// console.log("Hello", page.href);
page.style.pointerEvents = "none";
}
else{
page.style.pointerEvents = "all";
}
if (data.twitter_username == null) {
// console.log("Hello", page.href);
twitter.style.pointerEvents = "none";
}
else {
twitter.style.pointerEvents = "all";
}
}
else {
noresults.style.display = "block";
noresults.textContent = "no search results";
}
}
function init() {
darkMode = false;
const value = localStorage.getItem("dark-mode");
if (value == null) {
localStorage.setItem("dark-mode", darkMode);
activateLightMode();
}
else if (value == "true")
activateDarkMode();
else if (value == "false")
activateLightMode();
getUserData(url + 'jayant-baid');
}
init();