Skip to content

Instantly share code, notes, and snippets.

@Nicola1971
Forked from lsloan/ List GitHub Projects Using jQuery
Last active December 13, 2016 22:38
Show Gist options
  • Save Nicola1971/8d9194e0cb40998606a2b545d2908eb3 to your computer and use it in GitHub Desktop.
Save Nicola1971/8d9194e0cb40998606a2b545d2908eb3 to your computer and use it in GitHub Desktop.
// http://aboutcode.net/2010/11/11/list-github-projects-using-javascript.html
jQuery.githubUserRepositories = 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 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;
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment