-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
313 lines (270 loc) · 10.7 KB
/
script.js
File metadata and controls
313 lines (270 loc) · 10.7 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
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
// GitHub API configuration
const GITHUB_API_BASE = 'https://api.github.com';
const REPOS_PER_PAGE = 100; // Maximum repos to analyze
// Language colors for tech stack visualization
const LANGUAGE_COLORS = {
'JavaScript': '#f1e05a',
'TypeScript': '#2b7489',
'Python': '#3572A5',
'Java': '#b07219',
'C++': '#f34b7d',
'C#': '#178600',
'Go': '#00ADD8',
'Rust': '#dea584',
'PHP': '#4F5D95',
'Ruby': '#701516',
'Swift': '#ffac45',
'Kotlin': '#F18E33',
'Dart': '#00B4AB',
'Scala': '#c22d40',
'R': '#198CE7',
'MATLAB': '#e16737',
'Shell': '#89e051',
'HTML': '#e34c26',
'CSS': '#563d7c',
'Vue': '#2c3e50',
'React': '#61dafb',
'Angular': '#dd0031',
'Svelte': '#ff3e00',
'Solidity': '#363636',
'Assembly': '#6E4C13',
'C': '#555555',
'Objective-C': '#438eff',
'Perl': '#0298c3',
'Lua': '#000080',
'Haskell': '#5D4F85',
'Clojure': '#db5855',
'Elixir': '#6e4a7e',
'Erlang': '#B83998',
'F#': '#b845fc',
'OCaml': '#3be133',
'Racket': '#3c5caa',
'Scheme': '#1f4f79',
'Prolog': '#74283c',
'COBOL': '#d4d4d4',
'Fortran': '#4d41b1',
'Ada': '#02f88c',
'Lisp': '#3fb68b',
'Groovy': '#e69f56',
'PowerShell': '#012456',
'Batchfile': '#C1F12E',
'Makefile': '#427819',
'Dockerfile': '#384d54',
'YAML': '#cb171e',
'JSON': '#000000',
'Markdown': '#083fa1',
'TeX': '#3D6117',
'Jupyter Notebook': '#DA5B0B',
'Vim script': '#199f4b',
'Emacs Lisp': '#c065db',
'VimL': '#199f4b',
'Nix': '#7e7eff',
'Nim': '#ffc200',
'Crystal': '#000100',
'Zig': '#ec915c',
'V': '#4f87c4',
'Carbon': '#5E8C31',
'Mojo': '#ff4c4c',
'default': '#6f42c1'
};
class GitHubAnalyzer {
constructor() {
this.initializeEventListeners();
this.currentUser = null;
}
initializeEventListeners() {
const searchBtn = document.getElementById('search-btn');
const usernameInput = document.getElementById('username-input');
searchBtn.addEventListener('click', () => this.searchUser());
usernameInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
this.searchUser();
}
});
}
async searchUser() {
const username = document.getElementById('username-input').value.trim();
if (!username) {
this.showError('Please enter a GitHub username');
return;
}
this.showLoading();
this.hideError();
this.hideProfile();
try {
const userData = await this.fetchUserProfile(username);
const reposData = await this.fetchUserRepositories(username);
this.currentUser = { ...userData, repositories: reposData };
this.displayProfile(this.currentUser);
this.analyzeTechStack(this.currentUser);
this.displayRepositories(this.currentUser.repositories);
} catch (error) {
console.error('Error:', error);
this.showError(error.message || 'Failed to fetch user data');
} finally {
this.hideLoading();
}
}
async fetchUserProfile(username) {
const response = await fetch(`${GITHUB_API_BASE}/users/${username}`);
if (!response.ok) {
if (response.status === 404) {
throw new Error('User not found. Please check the username and try again.');
} else if (response.status === 403) {
throw new Error('Rate limit exceeded. Please try again later.');
} else {
throw new Error(`Failed to fetch user profile (${response.status})`);
}
}
return await response.json();
}
async fetchUserRepositories(username) {
const response = await fetch(
`${GITHUB_API_BASE}/users/${username}/repos?per_page=${REPOS_PER_PAGE}&sort=updated`
);
if (!response.ok) {
throw new Error('Failed to fetch repositories');
}
return await response.json();
}
displayProfile(user) {
// Update profile information
document.getElementById('avatar').src = user.avatar_url;
document.getElementById('display-name').textContent = user.name || user.login;
document.getElementById('username').textContent = `@${user.login}`;
document.getElementById('bio').textContent = user.bio || 'No bio available';
document.getElementById('followers-count').textContent = user.followers;
document.getElementById('following-count').textContent = user.following;
document.getElementById('repos-count').textContent = user.public_repos;
this.showProfile();
}
analyzeTechStack(user) {
const languageStats = {};
let totalBytes = 0;
// Count languages from repositories
user.repositories.forEach(repo => {
if (repo.language && !repo.fork) {
const language = repo.language;
if (!languageStats[language]) {
languageStats[language] = { count: 0, bytes: 0 };
}
languageStats[language].count++;
// Estimate bytes based on repo size (stars as proxy for size)
const estimatedBytes = (repo.stargazers_count + 1) * 1000;
languageStats[language].bytes += estimatedBytes;
totalBytes += estimatedBytes;
}
});
// Calculate percentages and sort by usage
const techStack = Object.entries(languageStats)
.map(([language, stats]) => ({
language,
count: stats.count,
percentage: totalBytes > 0 ? (stats.bytes / totalBytes) * 100 : 0,
color: LANGUAGE_COLORS[language] || LANGUAGE_COLORS.default
}))
.sort((a, b) => b.percentage - a.percentage)
.slice(0, 10); // Top 10 languages
this.displayTechStack(techStack);
}
displayTechStack(techStack) {
const techStackContainer = document.getElementById('tech-stack');
techStackContainer.innerHTML = '';
if (techStack.length === 0) {
techStackContainer.innerHTML = '<p class="no-data">No language data available</p>';
return;
}
techStack.forEach(tech => {
const techItem = document.createElement('div');
techItem.className = 'tech-item';
techItem.innerHTML = `
<div class="tech-name">${tech.language}</div>
<div class="tech-percentage">${tech.percentage.toFixed(1)}%</div>
<div class="tech-bar">
<div class="tech-bar-fill" style="width: ${tech.percentage}%; background-color: ${tech.color}"></div>
</div>
`;
techStackContainer.appendChild(techItem);
});
}
displayRepositories(repositories) {
const reposContainer = document.getElementById('repositories');
reposContainer.innerHTML = '';
if (repositories.length === 0) {
reposContainer.innerHTML = '<p class="no-data">No repositories found</p>';
return;
}
// Sort by stars and forks
const sortedRepos = repositories
.sort((a, b) => (b.stargazers_count + b.forks_count) - (a.stargazers_count + a.forks_count))
.slice(0, 12); // Show top 12 repos
sortedRepos.forEach(repo => {
const repoCard = document.createElement('div');
repoCard.className = 'repo-card';
const languageColor = repo.language ? (LANGUAGE_COLORS[repo.language] || LANGUAGE_COLORS.default) : 'transparent';
repoCard.innerHTML = `
<div class="repo-name">
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
<path d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5v-9zm10.5-1V9h-8c-.356 0-.694.074-1 .208v-1.44A1.5 1.5 0 0 1 4.5 6h8zM5 12.25v-3.5a.75.75 0 0 1 1.5 0v3.5a.75.75 0 0 1-1.5 0z"/>
</svg>
<a href="${repo.html_url}" target="_blank" rel="noopener noreferrer">${repo.name}</a>
</div>
<div class="repo-description">${repo.description || 'No description available'}</div>
<div class="repo-meta">
${repo.language ? `<span><div class="repo-language" style="background-color: ${languageColor}"></div>${repo.language}</span>` : ''}
<span>⭐ ${repo.stargazers_count}</span>
<span>🍴 ${repo.forks_count}</span>
<span>📅 ${new Date(repo.updated_at).toLocaleDateString()}</span>
</div>
`;
reposContainer.appendChild(repoCard);
});
}
// UI State Management
showLoading() {
document.getElementById('loading').classList.remove('hidden');
}
hideLoading() {
document.getElementById('loading').classList.add('hidden');
}
showError(message) {
const errorElement = document.getElementById('error');
const errorMessage = document.getElementById('error-message');
errorMessage.textContent = message;
errorElement.classList.remove('hidden');
}
hideError() {
document.getElementById('error').classList.add('hidden');
}
showProfile() {
document.getElementById('profile-section').classList.remove('hidden');
}
hideProfile() {
document.getElementById('profile-section').classList.add('hidden');
}
}
// Initialize the application
document.addEventListener('DOMContentLoaded', () => {
new GitHubAnalyzer();
});
// Add some additional styling for better visual feedback
document.addEventListener('DOMContentLoaded', () => {
// Add smooth scrolling
document.documentElement.style.scrollBehavior = 'smooth';
// Add focus styles for better accessibility
const searchInput = document.getElementById('username-input');
searchInput.addEventListener('focus', () => {
searchInput.parentElement.style.transform = 'scale(1.02)';
});
searchInput.addEventListener('blur', () => {
searchInput.parentElement.style.transform = 'scale(1)';
});
// Example username click functionality
const exampleUsername = document.querySelector('.example-username');
if (exampleUsername) {
exampleUsername.addEventListener('click', function() {
searchInput.value = 'noahkhomer18';
searchInput.focus();
});
}
});