-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
69 lines (64 loc) · 2.96 KB
/
script.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
// JavaScript (script.js)
function fetchGitHubStats() {
const inputUsername = document.getElementById('github-username').value;
// Check if a username is provided
if (!inputUsername) {
// Display GitHub logo as initial state
const githubStatsElement = document.getElementById('github-stats');
githubStatsElement.innerHTML = `
<div class="github-stats-container">
<img src="github.png" alt="GitHub Logo" width="550px">
<p class="initial-state">Enter a GitHub username to get stats.</p>
</div>`;
return;
}
const apiUrl = `https://api.github.com/users/${inputUsername}`;
// Fetch GitHub user data
fetch(apiUrl)
.then(response => response.json())
.then(data => {
// Extract relevant GitHub user stats
const {
login,
name,
bio,
avatar_url,
location,
public_repos,
followers,
following,
created_at,
updated_at,
blog,
twitter_username,
company,
email,
public_gists,
} = data;
// Dynamically create HTML content for user stats
const githubStatsElement = document.getElementById('github-stats');
githubStatsElement.innerHTML = `
<div class="github-stats-container">
<img src="${avatar_url}" alt="User Photo" class="user-photo">
<h2>${name || login}'s GitHub Stats</h2>
<p class="stats-item">Username: ${login}</p>
<p class="stats-item">Bio: ${bio || 'Not specified'}</p>
<p class="stats-item">Location: ${location || 'Not specified'}</p>
<p class="stats-item">Repositories: ${public_repos}</p>
<p class="stats-item">Gists: ${public_gists}</p>
<p class="stats-item">Followers: ${followers}</p>
<p class="stats-item">Following: ${following}</p>
<p class="stats-item">Member since: ${new Date(created_at).toLocaleDateString()}</p>
<p class="stats-item">Last updated: ${new Date(updated_at).toLocaleDateString()}</p>
<p class="stats-item">Website: ${blog ? ['<a href="https://' + blog + '">' + blog + '</a>'] : 'Not specified'}</p>
<p class="stats-item">Twitter: ${twitter_username || 'Not specified'}</p>
<p class="stats-item">Company: ${company || 'Not specified'}</p>
<p class="stats-item">Email: ${email || 'Not specified'}</p>
</div>
`;
})
.catch(error => {
console.error('Error fetching GitHub data:', error);
document.getElementById('github-stats').innerHTML = 'Error fetching GitHub data';
});
}