Skip to content

Instantly share code, notes, and snippets.

@mateusortiz
Last active November 27, 2019 02:02
Show Gist options
  • Save mateusortiz/1651a0ee191d64159b00 to your computer and use it in GitHub Desktop.
Save mateusortiz/1651a0ee191d64159b00 to your computer and use it in GitHub Desktop.
GitHub API Contributors - List all contributors of project
(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);
@raphamorim
Copy link

Sugestão: Use appendChild ou insertAdjacentHTML para substituir o innerHTML. Vai ficar melhor nesse caso. http://stackoverflow.com/questions/2305654/innerhtml-vs-appendchildtxtnode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment