-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (43 loc) · 1.25 KB
/
script.js
File metadata and controls
46 lines (43 loc) · 1.25 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
function getProfile() {
const username = document.getElementById("username").value;
const profile = document.getElementById("profile");
if (!username) {
profile.classList.remove("hidden");
profile.innerHTML = "<p>Please enter a username</p>";
return;
}
fetch(`https://api.github.com/users/${username}`)
.then(res => {
if (!res.ok) throw new Error("User not found");
return res.json();
})
.then(data => {
profile.classList.remove("hidden");
profile.innerHTML = `
<img src="${data.avatar_url}">
<h2>${data.name || data.login}</h2>
<p>${data.bio || "No bio available"}</p>
<div class="stats">
<div>
<strong>${data.followers}</strong>
<p>Followers</p>
</div>
<div>
<strong>${data.following}</strong>
<p>Following</p>
</div>
<div>
<strong>${data.public_repos}</strong>
<p>Repos</p>
</div>
</div>
<div>
<button onclick="window.open('${data.html_url}', '_blank')">View GitHub Profile</button>
</div>
`;
})
.catch(() => {
profile.classList.remove("hidden");
profile.innerHTML = "<p>❌ User not found</p>";
});
}