Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 40 additions & 44 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
```html
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -16,49 +15,46 @@ <h1>GitHub Profile Viewer</h1>
</div>

<script src="script.js"></script>
</body>
</html>

<script>
document.addEventListener('DOMContentLoaded', () => {
const searchBtn = document.getElementById('search-btn');
searchBtn.addEventListener('click', getProfile);
});
<script>
document.addEventListener("DOMContentLoaded", () => {
const searchBtn = document.getElementById("search-btn");
searchBtn.addEventListener("click", getProfile);
});

function getProfile() {
const username = document.getElementById('username').value.trim();
if (username) {
const profileDiv = document.getElementById('profile');
profileDiv.innerHTML = '';
const xhr = new XMLHttpRequest();
xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 300) {
const profileData = JSON.parse(xhr.responseText);
renderProfile(profileData);
} else {
profileDiv.innerHTML = `Error: ${xhr.statusText}`;
}
};
xhr.onerror = function() {
profileDiv.innerHTML = 'Error: Network request failed';
};
xhr.open('GET', `https://api.github.com/users/${username}`, true);
xhr.send();
} else {
alert('Please enter a GitHub username');
function getProfile() {
const username = document.getElementById("username").value.trim();
if (username) {
const profileDiv = document.getElementById("profile");
profileDiv.innerHTML = "";
const xhr = new XMLHttpRequest();
xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 300) {
const profileData = JSON.parse(xhr.responseText);
renderProfile(profileData);
} else {
profileDiv.innerHTML = "Error: " + xhr.statusText;
}
};
xhr.onerror = function() {
profileDiv.innerHTML = "Error: Network request failed";
};
xhr.open("GET", "https://api.github.com/users/" + username, true);
xhr.send();
} else {
alert("Please enter a GitHub username");
}
}
}

function renderProfile(profileData) {
const profileDiv = document.getElementById('profile');
const profileHTML = `
<h2>${profileData.name}</h2>
<p>Username: ${profileData.login}</p>
<p>Profile URL: <a href="${profileData.html_url}">${profileData.html_url}</a></p>
<p>Email: ${profileData.email}</p>
<p>Bio: ${profileData.bio}</p>
`;
profileDiv.innerHTML = profileHTML;
}
</script>
```
function renderProfile(profileData) {
const profileDiv = document.getElementById("profile");
const profileHTML =
"<h2>" + profileData.name + "</h2>" +
"<p>Username: " + profileData.login + "</p>" +
'<p>Profile URL: <a href="' + profileData.html_url + '">' + profileData.html_url + '</a></p>' +
"<p>Email: " + profileData.email + "</p>" +
"<p>Bio: " + profileData.bio + "</p>";
profileDiv.innerHTML = profileHTML;
}
</script>
</body>
</html>