-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.js
164 lines (108 loc) · 4.44 KB
/
profile.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
const usernameheading = document.getElementById('usernameheading');
//******************************** Functions *****************************//
function updateProfile(data)
{
// console.log(data);
const login = data.login;
const url = data.html_url;
const avatar_url = data.avatar_url;
const name = data.name;
const followers = data.followers;
const following = data.following;
const public_repos = data.public_repos;
document.getElementById('usernameheading').innerHTML = login;
document.getElementById('avatarurl').src = avatar_url;
document.getElementById('profileurl').href = url;
document.getElementById('fullname').innerHTML = name;
document.getElementById('repocount').innerHTML = public_repos;
document.getElementById('followercount').innerHTML = followers;
document.getElementById('followingcount').innerHTML = following;
}
function updateRepoList(data)
{
// console.log(data); // array format
let size = data.length;
if(size==0)
{
document.getElementById('repoList').innerHTML = `
<h3 class="text-light text-center mb-5">User with username '${username1}' has not created any repository yet</h3>
`;
return;
}
// console.log(size);
str=``;
for(let i=0;i<size;i++)
{
currdata = data[i];
console.log(currdata);
str += `
<div class="col mb-5 brad">
<div class="card" id="rcard">
<div class="card-body fs-4 position-relative">
<h2 class="card-title text-center fs-3">
${currdata.name ? currdata.name.slice(0,50):"Unnamed"}
</h2>
<hr />
<p class="card-text">Description :</p>
<p>
${currdata.description ? currdata.description.slice(0,50):currdata.name}
</p>
<p class="card-text">Created on : ${currdata.created_at}</p>
<p class="card-text">Open Issues : ${currdata.open_issues}</p>
<div class="position-absolute fixed-bottom pb-5">
<hr />
<div class="d-flex justify-content-around">
<a href="${currdata.created_at}" class="btn btn-primary fs-4">Visit Repository</a>
<a href="${currdata.homepage}" class="btn btn-success fs-4 ${!(currdata.homepage && currdata.homepage.length) ? "disabled" : "active"}">Visit Deployment</a>
</div>
</div>
</div>
</div>
</div>
`;
}
document.getElementById('repoList').innerHTML = str;
}
async function getRepoList(oldData)
{
// console.log(data);
// const login = data.login;
let repos_url = oldData.repos_url;
let response = await fetch(repos_url);
let data = await response.json()
updateRepoList(data);
}
function uodateStatsCars(data)
{
// console.log(data);
const login = data.login;
document.getElementById('st1img').src = `https://github-readme-stats.vercel.app/api/top-langs?username=${login}&show_icons=true&locale=en&layout=compact&theme=radical`;
document.getElementById('st2img').src = `https://github-readme-stats.vercel.app/api?username=${login}&show_icons=true&locale=en&theme=radical`;
document.getElementById('st3img').src = `https://github-readme-streak-stats.herokuapp.com/?user=${login}&theme=radical`;
document.getElementById('st4img').src = `https://github-readme-activity-graph.cyclic.app/graph?username=${login}&bg_color=0D1117&color=5BCDEC&line=5BCDEC&point=FFFFFF&hide_border=true`;
}
async function fetchDataFromApi(username) {
let URL = `https://api.github.com/users/${username}`;
const response = await fetch(URL);
// waits until the request completes...
const data = await response.json();
if(data.message)
{
window.location.replace(`/github-wrapper-javascript/404.html`);
// window.location.replace(`/404.html`);
}
updateProfile(data);
getRepoList(data);
uodateStatsCars(data);
}
function getUsernameFromUrl() {
// http://127.0.0.1:5500/profile.html?Pratham2301
let url = document.URL;
let userid = url.split("profile.html?")[1];
usernameheading.innerHTML = userid;
return userid;
}
//******************************** Main Code *****************************//
const username1 = getUsernameFromUrl();
// console.log(username1);
fetchDataFromApi(username1);