Created
September 29, 2017 03:17
-
-
Save marifrahman/aa026cc2298f59b93b5b652a20c32d09 to your computer and use it in GitHub Desktop.
Javascript to load all github projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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