-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d39ad7
commit 38e3ef0
Showing
4 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="styles.css"> | ||
<script defer src="scripts.js"></script> | ||
<link rel="icon" href="logo.png" type="image/png"> | ||
<title>GitHub User Stats</title> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<h1>GitHub User Stats</h1> | ||
<div id="search-container"> | ||
<label for="searchInput">Enter GitHub username:</label> | ||
<input type="text" id="searchInput" placeholder="Type a username" onkeydown="searchOnEnter(event)"> | ||
<button onclick="getUserStats()">Search</button> | ||
</div> | ||
<div id="userStats" class="hidden"></div> | ||
</div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
async function getUserStats() { | ||
const username = document.getElementById("searchInput").value; | ||
const userStatsContainer = document.getElementById("userStats"); | ||
|
||
if (username.trim() === "") { | ||
alert("Please enter a valid GitHub username."); | ||
userStatsContainer.classList.add("hidden"); | ||
return; | ||
} | ||
|
||
try { | ||
const response = await fetch(`https://api.github.com/users/${username}`); | ||
const userData = await response.json(); | ||
|
||
if (response.status === 200) { | ||
displayUserStats(userData); | ||
userStatsContainer.classList.remove("hidden"); | ||
} else { | ||
alert(`Error: ${userData.message}`); | ||
userStatsContainer.classList.add("hidden"); | ||
} | ||
} catch (error) { | ||
console.error("Error fetching data:", error); | ||
alert("An error occurred while fetching data. Please try again later."); | ||
userStatsContainer.classList.add("hidden"); | ||
} | ||
} | ||
|
||
function displayUserStats(userData) { | ||
const userStatsContainer = document.getElementById("userStats"); | ||
userStatsContainer.innerHTML = ` | ||
<h2>${userData.login}</h2> | ||
<img src="${userData.avatar_url}" alt="Profile Image"> | ||
<p><strong>Followers:</strong> <code>${userData.followers}</code></p> | ||
<p><strong>Following:</strong> <code>${userData.following}</code></p> | ||
<p><strong>Public Repositories:</strong> <code>${userData.public_repos}</code></p> | ||
<p><strong>Joined GitHub on:</strong> <code>${new Date(userData.created_at).toLocaleDateString()}</code></p> | ||
<p><strong>Location:</strong> <code>${userData.location || "Not specified"}</code></p> | ||
<p><strong>Email:</strong> <code>${userData.email || "Not specified"}</code></p> | ||
<p><strong>Company:</strong> <code>${userData.company || "Not specified"}</code></p> | ||
<p><strong>Blog:</strong> ${userData.blog ? `<a href="${userData.blog}" target="_blank">${userData.blog}</a>` : "Not specified"}</p> | ||
<p><strong>Repos:</strong> ${userData.public_repos > 0 ? `<code>${userData.public_repos}</code>` : "No public repositories"}</p> | ||
<p><strong>Gists:</strong> ${userData.public_gists > 0 ? `<code>${userData.public_gists}</code>` : "No public gists"}</p> | ||
`; | ||
} | ||
|
||
function searchOnEnter(event) { | ||
if (event.key === "Enter") { | ||
getUserStats(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
:root { | ||
--primary-color: #61dafb; | ||
--background-color: #282c35; | ||
--container-background: #38424d; | ||
--border-color: #485363; | ||
--text-color: #ffffff; | ||
} | ||
|
||
body { | ||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | ||
margin: 0; | ||
padding: 0; | ||
background-color: var(--background-color); | ||
color: var(--text-color); | ||
} | ||
|
||
.container { | ||
max-width: 800px; | ||
margin: 50px auto; | ||
padding: 20px; | ||
border: 1px solid var(--border-color); | ||
border-radius: 8px; | ||
box-shadow: 0 0 20px rgba(255, 255, 255, 0.1); | ||
background-color: var(--container-background); | ||
animation: fadeIn 1s ease-in-out; | ||
} | ||
|
||
@keyframes fadeIn { | ||
from { | ||
opacity: 0; | ||
} | ||
|
||
to { | ||
opacity: 1; | ||
} | ||
} | ||
|
||
h1 { | ||
text-align: center; | ||
color: var(--primary-color); | ||
} | ||
|
||
code { | ||
background-color: #4d5766; | ||
color: var(--text-color); | ||
padding: 2px 4px; | ||
border-radius: 4px; | ||
} | ||
|
||
hr { | ||
border: 1px solid var(--border-color); | ||
margin: 20px 0; | ||
} | ||
|
||
a { | ||
color: var(--primary-color); | ||
text-decoration: none; | ||
} | ||
|
||
a:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
#search-container { | ||
margin-bottom: 20px; | ||
text-align: center; | ||
} | ||
|
||
label { | ||
margin-right: 10px; | ||
} | ||
|
||
#searchInput { | ||
padding: 10px; | ||
border: 1px solid var(--border-color); | ||
border-radius: 4px; | ||
margin-right: 5px; | ||
width: 60%; | ||
box-sizing: border-box; | ||
} | ||
|
||
button { | ||
padding: 10px; | ||
background-color: var(--primary-color); | ||
color: var(--text-color); | ||
border: none; | ||
border-radius: 4px; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
background-color: #4fa3f7; | ||
} | ||
|
||
#userStats { | ||
margin-top: 20px; | ||
text-align: center; | ||
} | ||
|
||
#userStats h2 { | ||
color: var(--primary-color); | ||
margin-bottom: 10px; | ||
} | ||
|
||
#userStats img { | ||
width: 150px; | ||
height: 150px; | ||
border-radius: 50%; | ||
margin-bottom: 20px; | ||
} | ||
|
||
#userStats p { | ||
margin: 10px 0; | ||
text-align: left; | ||
} | ||
|
||
#userStats strong { | ||
color: var(--primary-color); | ||
} | ||
|
||
#userStats code { | ||
background-color: #4d5766; | ||
color: var(--text-color); | ||
padding: 2px 4px; | ||
border-radius: 4px; | ||
font-family: 'Courier New', Courier, monospace; | ||
} | ||
|
||
#userStats a { | ||
color: var(--primary-color); | ||
text-decoration: none; | ||
} | ||
|
||
#userStats a:hover { | ||
text-decoration: underline; | ||
} |