-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
76 lines (66 loc) · 2.17 KB
/
script.js
File metadata and controls
76 lines (66 loc) · 2.17 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
const username = 'codedbycj';
async function fetchGitHubData() {
try {
const profileRes = await fetch(`https://api.github.com/users/${username}`);
if (!profileRes.ok) throw new Error('Profile fetch failed');
const profile = await profileRes.json();
document.getElementById('avatar').src = profile.avatar_url;
document.getElementById('username').textContent = profile.login.toUpperCase();
document.getElementById('bio').textContent = profile.bio || "No bio available";
const reposRes = await fetch(`https://api.github.com/users/${username}/repos?per_page=100`);
if (!reposRes.ok) throw new Error('Repos fetch failed');
const repos = await reposRes.json();
renderRepoList(repos);
renderSkillsChart(repos);
} catch (error) {
console.error(error);
alert('Failed to load GitHub data. Check console for details.');
}
}
function renderRepoList(repos) {
const repoList = document.getElementById('repo-list');
repoList.innerHTML = '';
repos.forEach(repo => {
const li = document.createElement('li');
li.innerHTML = `
<a href="${repo.html_url}" target="_blank">${repo.name}</a> - ⭐ ${repo.stargazers_count} - Forks: ${repo.forks_count}
<p>${repo.description || 'No description'}</p>
`;
repoList.appendChild(li);
});
}
function renderSkillsChart(repos) {
// Count languages
const langCount = {};
repos.forEach(repo => {
const lang = repo.language;
if (lang) langCount[lang] = (langCount[lang] || 0) + 1;
});
const labels = Object.keys(langCount);
const data = Object.values(langCount);
const ctx = document.getElementById('skills-chart').getContext('2d');
new Chart(ctx, {
type: 'doughnut',
data: {
labels,
datasets: [{
label: 'Repositories by Language',
data,
backgroundColor: [
'#0366d6', '#f1e05a', '#e34c26', '#563d7c', '#6f42c1', '#c6538c', '#1f8dd6'
],
borderWidth: 1
}]
},
options: {
responsive: true,
plugins: {
legend: {
position: 'bottom'
}
}
}
});
}
// Initialize app
fetchGitHubData();