Skip to content

Commit 1a8b231

Browse files
github user data
0 parents  commit 1a8b231

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

get_github_data.html

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Github Followers</title>
6+
</head>
7+
<body>
8+
<div id="userForm">
9+
<form method="post">
10+
<input type="text" id="_txtUserName" name="_txtUserName" placeholder="github username" value="octocat">
11+
<button type="button" id="button">Get Github Followers</button>
12+
</form>
13+
</div>
14+
<div id="displayUserProfile"></div>
15+
<script charset="utf-8" type="text/javascript">
16+
var _userName;
17+
document.getElementById("button").addEventListener("click", function() {
18+
if (!document.getElementById("_txtUserName").value) {
19+
alert("Please enter valid username");
20+
return false;
21+
} else {
22+
_userName = document.getElementById("_txtUserName").value;
23+
var xhttp = new XMLHttpRequest();
24+
var _userProfileDetails = "https://api.github.com/users/" + _userName;
25+
var _userFollowerDetails = "https://api.github.com/users/" + _userName + "/followers";
26+
var _userFollowingDetails = "https://api.github.com/users/" + _userName + "/following";
27+
var _userGistsDetails = "https://api.github.com/users/" + _userName + "/gists";
28+
var _userStarredDetails = "https://api.github.com/users/" + _userName + "/starred";
29+
xhttp.onreadystatechange = function() {
30+
if (this.readyState == 4 && this.status == 200) {
31+
var _responseData = JSON.parse(this.responseText);
32+
var bindData = document.getElementById("displayUserProfile");
33+
if (_responseData.length == undefined) {
34+
bindData.innerHTML +=
35+
`<div>
36+
<br>
37+
<span>UserId:- ` + _responseData.id + `</span>
38+
<img height="50px" width="50px" src="` + _responseData.avatar_url + `" />
39+
<a href="` + _responseData.html_url + `" target="_blank" ><span>Username:- ` + _responseData.login + `</span></a>
40+
<br>
41+
</div>`
42+
} else {
43+
for (var i = 0; i < _responseData.length; i++) {
44+
bindData.innerHTML +=
45+
`<div>
46+
<br>
47+
<span>UserId:- ` + _responseData[i].id + `</span>
48+
<img height="50px" width="50px" src="` + _responseData[i].avatar_url + `" />
49+
<a href="` + _responseData[i].html_url + `" target="_blank" ><span>Username:- ` + _responseData[i].login + `</span></a>
50+
<br>
51+
</div>`
52+
}
53+
}
54+
}
55+
};
56+
xhttp.open("GET", _userProfileDetails, true);
57+
xhttp.send();
58+
}
59+
});
60+
</script>
61+
</body>
62+
</html>

0 commit comments

Comments
 (0)