-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch.js
36 lines (35 loc) · 1.61 KB
/
fetch.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
// Retrieve the username from localStorage and display it
const username = localStorage.getItem("githubUsername");
const result = document.getElementById("result");
if (username) {
fetch(`https://api.github.com/users/${username}`)
.then((response) => response.json())
.then((data) => {
if (data.message && data.message === "Not Found") {
result.innerHTML = "<p> User not found ! </p>";
} else {
const data1 = `
<div class="container">
<div>
<h1>${username}</h1><br/>
<div id="pfp">
<a href="${data.html_url}" target="_blank"><img src="${data.avatar_url}" alt="${data.login}"></a>
</div>
<div class="contents">
<p class="info"><strong>Name : </strong> ${data.name}</p>
<p class="info"><strong>Username : </strong> ${data.login}</p>
<p class="info"><strong>Followers : </strong> ${data.followers}</p>
<p class="info"><strong>Following :</strong> ${data.following}</p>
<p class="info"><strong>Public Repositories : </strong> ${data.public_repos}</p>
</div>
</div>
</div>
`;
result.innerHTML = data1;
}
})
.catch((error) => {
console.error("Error", error);
result.innerHTML = "<p>Facing error while fetching data </p>";
});
}