-
Notifications
You must be signed in to change notification settings - Fork 1
/
github.js
79 lines (74 loc) · 1.99 KB
/
github.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
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
var totalDownloads = 0
$(document).ready(function() {
var UrlUser = getUrlVar("user");
var UrlRepo = getUrlVar("repo");
getDlCount(UrlUser, UrlRepo);
getRepo(UrlUser, UrlRepo);
});
function getUrlVar(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0; i<vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
};
};
return(false);
};
function getRepo(u, r) {
$.ajax({
url: "https://api.github.com/repos/" + u + "/" + r,
headers: {
// "Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD)
},
success:function(data) {
var repo = {
name : data.name,
forks : data.forks_count,
openIssues : data.open_issues_count,
stars : data.stargazers_count,
size : data.size,
owner : data.owner.login,
url : data.html_url
};
$("#name").text(repo.name);
$("#stars").text(repo.stars.toLocaleString());
$("#forks").text(repo.forks.toLocaleString());
$("#issues").text(repo.openIssues.toLocaleString());
$("#author").text(repo.owner);
$("#title-link").attr("href", repo.url)
return repo;
}
});
}
function getDlCount(u, r) {
var location = "https://api.github.com/repos/" + u + "/" + r + "/releases"
$.ajax({
url: location,
headers: {
// "Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD)
},
error:function (xhr, ajaxOptions, thrownError) {
if(xhr.status==404) {
$("#title-link").text("404 - check url string");
$("#title-link").css('textDecoration','none');
$(".info").hide();
$(".source").hide();
};
}
}).then(function(data) {
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < data[i]["assets"].length; j++) {
var c = data[i]["assets"][j]["download_count"];
totalDownloads += c;
};
};
if (totalDownloads > 0) {
$("#total-dl").text(totalDownloads.toLocaleString());
}
else {
$("#dl-container").hide()
}
});
};