-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
333 lines (299 loc) · 11.1 KB
/
index.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
// requiring dom-to-image....
// import domtoimage from '../node_modules/dom-to-image';
// requiring filesaver....
// import { saveAs } from '../node_modules/file-saver';
// Selecting elements....
const username = document.getElementById("name");
const gravatar = document.getElementById("gravatar");
const locdisp = document.getElementById("location");
const biodiv = document.getElementById("bio");
const numrepo = document.getElementById("numrepo");
const gists = document.getElementById("gists");
const orgsdiv = document.getElementById("orgs");
const orgtitle = document.getElementById("orgtitle");
const element = document.getElementById("maindiv");
const contentdiv = document.getElementById("con");
const stardiv = document.getElementById("stardiv");
const startitle = document.getElementById("startitle");
const submitbut = document.getElementById("submit");
const langtitle = document.getElementById("langtitle");
const profilelink = document.getElementById("profilelink");
const butdiv = document.getElementById("butdiv");
const inpdiv = document.getElementById("inpdiv");
// Create elements....
const hr = document.createElement("hr");
const countdiv = document.createElement("div");
const starimgdiv = document.createElement("div");
const stariconcontainerdiv = document.createElement("div");
// Action switcher....
let clickCounter = 0;
submitbut.onclick = function () {
clickCounter++;
if (clickCounter == 2) {
window.location.reload();
} else {
dta();
}
};
// ss function for screenshot.... // using html2canvas....
// function ss() {
// html2canvas(document.querySelector("#maindiv")).then((canvas) => {
// document.body.appendChild(canvas);
// });
// allowTaint = false;
// }
// ssjs function for screenshot.... // using normal js.... // almost working.... hurray ...........................
function ss(){
heightdiv = document.getElementById("ss").offsetHeight
console.log("heightdiv" + heightdiv); // this logs the current height of the element....
widthdiv = document.getElementById("ss").offsetWidth
console.log("Widthdiv" + widthdiv); // this logs the current width of the elemrnt....
if (typeof screen.orientation !== 'undefined'){ // This takes care of detecting mobile and adjusting the height and width accordingly....
console.log("i am mobile")
domtoimage.toBlob(document.getElementById('ss') , {"height" : 2000 , "width" : 1500}) // div is cropped here for suitable output..... {"height" : heightdiv , "width" : widthdiv}
.then(function (blob) {
saveAs(blob, `${username.textContent}.png`);
});
}
else{
console.log("i am pc")
domtoimage.toBlob(document.getElementById('ss') , {"height" : 500 , "width" : 1500}) // div is cropped here for suitable output..... {"height" : heightdiv , "width" : widthdiv}
.then(function (blob) {
saveAs(blob, `${username.textContent}.png`);
});
}
}
// // another screenshot method.... //ssjsbut
// $(function() {
// $("#ssjsbut").click(function() {
// html2canvas($('#gravatardiv').get(0)).then( function (canvas) {
// $("#body").append(canvas);
// });
// canvas.toBlob(function(blob) {
// saveAs(blob, "Dashboard.png");
// });
// })
// })
// on click function....
async function dta() {
let inputVal = document.getElementById("text").value;
// Making maindiv visible on button click....
if (element.style.display === "none") {
element.style.display = "block";
butdiv.style.display = "block";
} else {
element.style.display = "none";
butdiv.style.display = "none";
}
// Making content div invisible on the appearence of maindiv....
if (contentdiv.style.display === "block") {
contentdiv.style.display = "none";
// inpdiv.style.display = "none"; // needed for reload function in output screen....
} else {
contentdiv.style.display = "block";
// inpdiv.style.display = "block"; // needed for reload function in output screen....
ssjs()
}
// Base url for every request....
let baseURL = "https://api.github.com/users/";
// url to request for ....
let usrreq = baseURL + inputVal;
// await for the url and getting back the json....
const res = await fetch(usrreq);
const data = await res.json();
//console.log(data);
// for name....
let name = data.name;
// for location....
let loc = data.location;
// for profile link....
let profile = data.html_url;
// for gravatar....
let img = data.avatar_url;
// for bio....
let bio = data.bio;
// for public repos....
let prepo = data.public_repos;
// for gists count....
let pgists = data.public_gists;
// for organistation info....
let orginfo = data.organizations_url;
// let orglinksarray = [];
const orgdata1 = await fetch(orginfo);
const orgdata = await orgdata1.json();
// console.log(orgdata); // this line for debugging....
if (orgdata.length != 0) {
orgdata.forEach((i) => {
const orgname = i.login;
const orgavatar = i.avatar_url;
const orgurl = i.url; // organisation url for every organisation....
// console.log(orgname); // debug statement....
console.log(orgurl);
// orglinksarray.push(orgurl);
let orgimg = document.createElement("img"); // create a image element for organisations....
let orglink = document.createElement("a"); //create a link for organistaions....
orgimg.src = orgavatar;
orgimg.alt = orgname;
orgimg.className = "orimg";
orgsdiv.appendChild(orglink); // orlink is a anchor tag....
orglink.appendChild(orgimg); // image is inserted between anchor tags....
orglink.href = `https://github.com/${orgname}`;
orgtitle.textContent = "Organisations";
orgtitle.appendChild(hr);
});
}
// for star info....
let starsarray = [];
const lang = [];
let repourl = data.repos_url;
const repourl1 = await fetch(repourl);
const repodata = await repourl1.json();
console.log(repodata);
if (repodata.length != 0) {
repodata.forEach((j) => {
const eachstar = j.stargazers_count;
starsarray.push(eachstar);
});
let totalstars = starsarray.reduce(function (a, b) {
return a + b;
}, 0);
// final stars count....
console.log(totalstars);
let staricon = document.createElement("img");
staricon.src =
"./star.png";
staricon.alt = "Total stars";
staricon.className = "staricon";
stardiv.appendChild(stariconcontainerdiv);
stariconcontainerdiv.appendChild(starimgdiv);
starimgdiv.appendChild(staricon);
stariconcontainerdiv.appendChild(countdiv);
// stardiv.appendChild(staricon);
// stardiv.appendChild(span);
countdiv.textContent = `${totalstars}`;
countdiv.className = "starcount";
startitle.textContent = "Stars";
startitle.appendChild(hr);
// for most used languages....
repodata.forEach((k) => {
eachlang = k.language;
lang.push(eachlang);
});
// removing null fields from the lang array....
let filteredlang = lang.filter(function (el) {
return el != null;
});
// frequently used languages mechanism....
const num = 5;
const findMostFrequent = (num = 1) => {
const strArr = filteredlang; // filteredlang is a array with null fields removed....
const map = {};
strArr.forEach((word) => {
if (map.hasOwnProperty(word)) {
map[word]++;
} else {
map[word] = 1;
}
});
const frequencyArr = Object.keys(map).map((key) => [key, map[key]]);
frequencyArr.sort((a, b) => b[1] - a[1]);
return frequencyArr.slice(0, num).map((el) => el[0]);
};
const mostusedlangs = findMostFrequent(num);
console.log(mostusedlangs); // final languages top array....
// rendering lang title....
langtitle.textContent = "TOP LANGUAGES";
langtitle.appendChild(hr);
mostusedlangs.forEach((l) => {
$(".col1").append(
'<div id="toplangs"><dt class ="langdata">' + l + "</dt></div>"
); // dynamic language rendering....
});
}
// rendering on front end....
// to check for null fields....
if ((name == null) & (loc == null) & (img == null)) {
username.textContent = "OOPS not found ..";
} else {
username.textContent = name;
}
gravatar.src = img;
gravatar.alt = inputVal;
locdisp.textContent = loc;
biodiv.textContent = bio;
numrepo.textContent = prepo;
gists.textContent = pgists;
profilelink.href = profile;
// debug statements....
// console.log(name, loc);
// alert(inputVal);
}
// below code is written for a precaution purpose, it deletes duplicate images in the html document, in case of double fetching happens....
// var img = $("img");
// var used = {};
// console.dir($(img[0]).attr("src"));
// img.each(function () {
// var src = $(this).attr("src");
// if (used[src]) $(this).remove();
// used[src] = 1;
// });
// Theme toggler mechanism....
let themetoggler = 0;
document.getElementById("theme").onclick = function themetoggle () {
element.style.transition = "ease 2s"
themetoggler++;
if (themetoggler == 1) {
document.getElementById("theme").innerText = "bullseye" // changes inner text of the button....
theme1()
}
else if (themetoggler == 2){
document.getElementById("theme").innerText = "squares" // changes inner text of the button....
theme2()
}
else if (themetoggler == 3){
document.getElementById("theme").innerText = "inter" // changes inner text of the button....
theme3()
}
// incomplete white theme....
// else if (themetoggler == 4){
// document.getElementById("theme").innerText = "white" // changes inner text of the button....
// // theme4()
// }
// // else if (themetoggler == 5){
// // console.log("recurivse started.")
// // return themetoggle()
// // }
else{
themetoggler = null;
themetoggle()
}
};
// all theme changing functions....
function theme1() {
element.style.backgroundImage = "url('./Bullseye-Gradient.png')";
// document.body.style.backgroundImage = "url('img_tree.png')";
element.style.transition = "ease 2s"
}
function theme2(){
element.style.backgroundImage = "url('./Protruding-Squares.png')";
element.style.transition = "ease 2s"
}
function theme3(){
element.style.backgroundImage = "url('./Geometric-Intersection.png')";
element.style.transition = "ease 2s"
}
function theme4(){
// <a href='https://www.freepik.com/photos/background'>Background photo created by benzoix - www.freepik.com</a>
element.style.backgroundImage = "url('../img/grungy-white-background-natural-cement-stone-old-texture-as-retro-pattern-wall-conceptual-wall-banner-grunge-material-construction.jpg')";
document.getElementById("name").style.color = "#2f4f4f"
document.getElementById("location").style.color = "#2f4f4f"
document.getElementById("orgtitle").style.color = "#2f4f4f"
document.getElementById("bio").style.color = "#2f4f4f"
document.getElementById("startitle").style.color = "#2f4f4f"
document.getElementById("langtitle").style.color = "#2f4f4f"
// let langlistcolor = document.getElementById("toplangs").childNodes;
// console.log(langlistcolor);
document.getElementById("#toplangs").style.color = "#2f4f4f"
// document.querySelector("#toplangs > dt")
// console.log(langlistcolor);
}