Skip to content

Instantly share code, notes, and snippets.

@marifrahman
Created September 29, 2017 03:17
Show Gist options
  • Save marifrahman/aa026cc2298f59b93b5b652a20c32d09 to your computer and use it in GitHub Desktop.
Save marifrahman/aa026cc2298f59b93b5b652a20c32d09 to your computer and use it in GitHub Desktop.
Javascript to load all github projects
// Inspired by the code from http://jointheconversation.org
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 repositories...</span>");
var target = this;
$.githubUser(username, function(response) {
var repos = response.data;
sortByNumberOfWatchers(repos);
var list = $('<dl/>');
target.empty().append(list);
$(repos).each(function() {
if (!this.fork) {
list.append('<dt><a href="'+ this.html_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