-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-profile-finder.html
More file actions
151 lines (134 loc) · 3.53 KB
/
Copy pathgithub-profile-finder.html
File metadata and controls
151 lines (134 loc) · 3.53 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Github Profile Finder</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Segoe UI", sans-serif;
}
body {
background-color: #f0f4f8;
display: flex;
justify-content: center;
padding: 40px 20px;
}
.container {
background: white;
border-radius: 16px;
padding: 40px;
width: 100%;
max-width: 500px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}
h1 {
font-size: 1.8rem;
color: #1a1a2e;
margin-bottom: 24px;
}
.search-bar {
display: flex;
gap: 10px;
margin-bottom: 30px;
}
input {
flex: 1;
padding: 10px 16px;
border: 2px solid #e0e0e0;
border-radius: 8px;
font-size: 1rem;
outline: none;
transition: border-color 0.2s;
}
input:focus {
border-color: #4a90d9;
}
button {
padding: 10px 20px;
background-color: #4a90d9;
color: white;
border: none;
border-radius: 8px;
font-size: 1rem;
cursor: pointer;
transition: background 0.2s;
}
button:hover {
background-color: #357abd;
}
#result {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
text-align: center;
}
#result img {
border-radius: 50%;
width: 100px;
height: 100px;
object-fit: cover;
border: 3px solid #4a90d9;
margin-bottom: 8px;
}
#result h2 {
font-size: 1.4rem;
color: #1a1a2e;
}
#result p {
color: #666;
font-size: 0.95rem;
}
</style>
</head>
<body>
<div class="container">
<h1>GitHub Profile Finder</h1>
<div class="search-bar">
<input
type="text"
placeholder="Enter GitHub username"
id="username-input"
/>
<button id="search-btn">Search!</button>
</div>
<div id="result"></div>
</div>
<script>
let input = document.querySelector("#username-input");
let btn = document.querySelector("#search-btn");
let div = document.querySelector("#result");
btn.addEventListener("click", () => {
let username = input.value;
// console.log(username);
async function getProfile(username) {
try {
const response = await fetch(
`https://api.github.com/users/${username}`);
if(!response.ok) {
div.innerHTML = `<p style = "color: red;">User not found. Try again.</p>`;
return;
}
const data = await response.json();
// console.log(data);
div.innerHTML = `
<img src="${data.avatar_url}" width="100px">
<h2>${data.name}</h2>
<p>${data.bio}</p>
<p>Followers: ${data.followers}</p>
<p>Public Repos: ${data.public_repos}</p>
`;
} catch(error) {
div.innerHTML = `<p style="color: red;">Something went wrong. Check your connection.</p>`;
}
}
getProfile(username);
input.value = "";
});
</script>
</body>
</html>