-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathgithub_api.js
31 lines (31 loc) · 1002 Bytes
/
github_api.js
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
$(document).ready(function() {
users = []
repos = []
$(".ghbtn").each( function () {
var user = $(this).attr('user');
var repo = $(this).attr('repo');
repos.push(user + '/' + repo);
if (users.indexOf($(this).attr('user')) === -1) {
users.push($(this).attr('user'))
}
})
// console.log(1, users, repos)
for (var i = 0; i < users.length; i++) {
$.ajax({
type: "GET",
url: "https://api.github.com/users/" + users[i] + "/repos?per_page=100",
tryCount : 0,
retryLimit : 3,
async: true,
dataType: "json",
success: function (data) {
for (var i = 0; i < data.length; i++) {
if (repos.indexOf(data[i].full_name) !== -1) {
x = data[i].name;
$("div[repo='" + x + "']").children(".star").html('<i class="fa fa-star"></i> ' + data[i].stargazers_count)
$("div[repo='" + x + "']").children(".fork").html('<i class="fa fa-code-fork"></i> ' + data[i].forks_count)
}
}
}
})}
});