forked from msasanmh/msasanmh.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-query.js
36 lines (25 loc) · 1.75 KB
/
github-query.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
jQuery.githubUser = function(username, callback) {
jQuery.getJSON('https://api.github.com/users/'+username+'/repos?callback=?',callback)
}
jQuery.fn.loadRepositories = function(username) {
this.html("<span>Querying GitHub for " + username +"'s repositories...</span>");
var target = this;
$.githubUser(username, function(data) {
var repos = data.data; // JSON Parsing
sortByName(repos);
var list = $('<dl/>');
target.empty().append(list);
$(repos).each(function() {
if (this.name != (username.toLowerCase()+'.github.com')) {
list.append('<dt><a href="'+ (this.homepage?this.homepage:this.html_url) +'">' + this.name + '</a> <em>'+(this.language?('('+this.language+')'):'')+'</em></dt>');
list.append('<dd>' + this.description +'</dd>');
}
});
});
function sortByName(repos) {
repos.sort(function(a,b) {
return a.name - b.name;
});
}
};
// jQuery.githubUserRepositories = function(username, callback) { jQuery.getJSON("https://api.github.com/users/" + username + "/repos?callback=?", callback);} jQuery.fn.loadRepositores = function(username) { this.html("<span>Querying GitHub for repositories...</span>"); var target = this; $.githubUserRepositories(username, function(data) { var repos = data.data; sortByNumberOfWatchers(repos); var list = $('<dl/>'); target.empty().append(list); $(repos).each(function() { list.append('<dt><a href="'+ this.url +'">' + this.name + '</a></dt>'); list.append('<dd>' + this.description + '</dd>'); }); }); function sortByNumberOfWatchers(repos) { repos.sort(function(a,b) { return b.watchers - a.watchers; }); }};