Last active
March 2, 2016 08:32
-
-
Save lsongdev/19ab1937a54ba53306c6 to your computer and use it in GitHub Desktop.
show github star, forks and more .
This file contains hidden or 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
/** | |
* Github Widgets | |
* @author lsong | |
* @example | |
* | |
* <a href="https://github.com/song940/kelp/stargazers"> | |
* <github repo="song940/kelp" key="stargazers_count" ></github> Stargazers | |
* </a> | |
*/ | |
;(function(elements){ | |
for(var i=0, seq=0;i<elements.length;i++){ | |
;(function(element){ | |
var jsonp = 'jsonp_' + (++seq); | |
var key = element.getAttribute('key'); | |
var repo = element.getAttribute('repo'); | |
window[ jsonp ] = function(res){ | |
element.appendChild(document.createTextNode(res.data[ key ] || '')); | |
}; | |
var script = document.createElement('script'); | |
script.src = 'https://api.github.com/repos/' + repo + '?callback=' + jsonp; | |
script.async = true; | |
document.head.appendChild(script); | |
})(elements[i]); | |
} | |
})(document.getElementsByTagName('github')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment