Last active
November 27, 2019 02:02
-
-
Save mateusortiz/1651a0ee191d64159b00 to your computer and use it in GitHub Desktop.
GitHub API Contributors - List all contributors of project
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
(function (window, document) { | |
'use strict'; | |
// Callback function | |
function appendContributors() { | |
/*jshint validthis: true*/ | |
var result = JSON.parse(this.responseText), | |
tpl = '<li class="contributor" itemprop="itemListElement" itemscope itemtype="http://schema.org/Person"><a href="#"><img class="picture" width="90" height="90"></a></li>', | |
str = '', | |
div; | |
for (var i = 0; i < result.length; i++) { | |
div = document.createElement('div'); | |
div.innerHTML = tpl; | |
div.querySelector('a').href = result[i].html_url; | |
div.querySelector('img').src = result[i].avatar_url + '&size=180'; | |
str += div.innerHTML; | |
} | |
document.querySelector('.profile-list').innerHTML = str; | |
} | |
var url = "https://api.github.com/repos/webcomponents/webcomponents.github.io/contributors"; | |
var oReq = new XMLHttpRequest(); | |
oReq.addEventListener('load', appendContributors); | |
oReq.open("get", url, true); | |
oReq.send(); | |
})(window, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sugestão: Use appendChild ou insertAdjacentHTML para substituir o innerHTML. Vai ficar melhor nesse caso. http://stackoverflow.com/questions/2305654/innerhtml-vs-appendchildtxtnode