-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (27 loc) · 1.07 KB
/
script.js
File metadata and controls
32 lines (27 loc) · 1.07 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
async function getGitHubProfile() {
const username = document.getElementById('username').value.trim();
const profile = document.getElementById('profile');
if (!username) {
profile.innerHTML = "<p>Please enter a GitHub username.</p>";
return;
}
profile.innerHTML = "<p>Loading...</p>";
try {
const res = await fetch(`https://api.github.com/users/${username}`);
if (!res.ok) {
throw new Error("User not found");
}
const data = await res.json();
profile.innerHTML = `
<img src="${data.avatar_url}" alt="Profile Picture" />
<h2>${data.name || data.login}</h2>
<p><strong>Username:</strong> ${data.login}</p>
<p><strong>Bio:</strong> ${data.bio || "N/A"}</p>
<p><strong>Public Repos:</strong> ${data.public_repos}</p>
<p><strong>Followers:</strong> ${data.followers}</p>
<p><a href="${data.html_url}" target="_blank" style="color:#58a6ff">View Profile on GitHub</a></p>
`;
} catch (error) {
profile.innerHTML = `<p style="color:red;">${error.message}</p>`;
}
}