- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub.js
More file actions
Latest commit
79 lines (74 loc) · 1.99 KB
/
Copy pathgithub.js
File metadata and controls
79 lines (74 loc) · 1.99 KB
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
vartotalDownloads=0
$(document).ready(function(){
varUrlUser=getUrlVar("user");
varUrlRepo=getUrlVar("repo");
getDlCount(UrlUser,UrlRepo);
getRepo(UrlUser,UrlRepo);
});
functiongetUrlVar(variable){
varquery=window.location.search.substring(1);
varvars=query.split("&");
for(vari=0;i<vars.length;i++){
varpair=vars[i].split("=");
if(pair[0]==variable){
returnpair[1];
};
};
return(false);
};
functiongetRepo(u,r){
$.ajax({
url: "https://api.github.com/repos/"+u+"/"+r,
headers: {
// "Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD)
},
success:function(data){
varrepo={
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)
returnrepo;
}
});
}
functiongetDlCount(u,r){
varlocation="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(vari=0;i<data.length;i++){
for(varj=0;j<data[i]["assets"].length;j++){
varc=data[i]["assets"][j]["download_count"];
totalDownloads+=c;
};
};
if(totalDownloads>0){
$("#total-dl").text(totalDownloads.toLocaleString());
}
else{
$("#dl-container").hide()
}
});
};