-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
64 lines (61 loc) · 1.94 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>Github Profile Finder</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
img{width:100%;}
</style>
</head>
<body>
<div class="container">
<form id="userForm">
<div class="form-group">
<label>Github Username:</label>
<input type="text" id="username" class="form-control">
</div>
</form>
<div id="profile"></div>
</div>
<script>
function getProfile(e){
e.preventDefault();
var username = document.getElementById('username').value;
if(!username || username == ''){
username = 'pfalkenberg';
}
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if(xhttp.readyState == 4 && xhttp.status == 200){
var user = JSON.parse(xhttp.responseText);
document.getElementById('profile').innerHTML = `<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">${user.name}</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-3">
<img src="${user.avatar_url}">
</div>
<div class="col-md-9">
<span class="label label-primary">Public Repos ${user.public_repos}</span>
<span class="label label-danger">Public Gists ${user.public_gists}</span>
<br><br>
<ul class="list-group">
<li class="list-group-item">Website: ${user.blog}</li>
<li class="list-group-item">Email: ${user.email}</li>
</ul>
<a class="btn btn-default" target="_blank" href="${user.html_url}">Visit Github</a>
</div>
</div>
</div>
</div>`;
}
}
xhttp.open('GET', 'https://api.github.com/users/'+username, true);
xhttp.send();
}
document.getElementById('userForm').addEventListener('submit', getProfile, false);
</script>
</body>
</html>