File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed
Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 77 < script src ="https://cdn.tailwindcss.com "> </ script >
88</ head >
99< body >
10-
10+ < div class ="container ">
11+ < h1 > GitHub Profile Viewer</ h1 >
12+ < form id ="profileForm ">
13+ < input type ="text " id ="username " placeholder ="Enter GitHub username " required >
14+ < button type ="submit "> Search</ button >
15+ </ form >
16+ < div id ="profileContainer " class ="profile "> </ div >
17+ </ div >
18+
19+ < script src ="script.js "> </ script >
1120</ body >
1221</ html >
Original file line number Diff line number Diff line change 1+ document . getElementById ( 'profileForm' ) . addEventListener ( 'submit' , function ( event ) {
2+ event . preventDefault ( ) ;
3+ const username = document . getElementById ( 'username' ) . value ;
4+ fetchGitHubProfile ( username ) ;
5+ } ) ;
6+
7+ async function fetchGitHubProfile ( username ) {
8+ const profileContainer = document . getElementById ( 'profileContainer' ) ;
9+ profileContainer . innerHTML = '' ;
10+
11+ try {
12+ const response = await fetch ( `https://api.github.com/users/${ username } ` ) ;
13+ if ( ! response . ok ) throw new Error ( 'Profile not found' ) ;
14+
15+ const profileData = await response . json ( ) ;
16+ displayProfile ( profileData ) ;
17+ } catch ( error ) {
18+ profileContainer . innerHTML = `<p>${ error . message } </p>` ;
19+ }
20+ }
21+
22+ function displayProfile ( profile ) {
23+ const profileHTML = `
24+ <img src="${ profile . avatar_url } " alt="Avatar" class="avatar">
25+ <div class="profile-info">
26+ <h2>${ profile . name } </h2>
27+ <p><strong>Username:</strong> ${ profile . login } </p>
28+ <p><strong>Followers:</strong> ${ profile . followers } </p>
29+ <p><strong>Following:</strong> ${ profile . following } </p>
30+ <p><strong>Public Repos:</strong> ${ profile . public_repos } </p>
31+ <a href="${ profile . html_url } " target="_blank">Visit Profile</a>
32+ </div>
33+ ` ;
34+ document . getElementById ( 'profileContainer' ) . innerHTML = profileHTML ;
35+ }
You can’t perform that action at this time.
0 commit comments