Skip to content

Instantly share code, notes, and snippets.

@marceloneil
Forked from mindplay-dk/github.xml
Last active April 13, 2016 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marceloneil/2166b912c090132fc4607e51f2e9ac5b to your computer and use it in GitHub Desktop.
Save marceloneil/2166b912c090132fc4607e51f2e9ac5b to your computer and use it in GitHub Desktop.
GitHub Gadget for Blogger
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="GitHub Activity" />
<UserPref name="username" display_name="marceloneil" required="true" />
<Content type="html">
<![CDATA[
<h2>GitHub Activity</h2>
<div id="github-activity"></div>
<script type="text/javascript">
var prefs = new gadgets.Prefs();
window.renderGitHubWidget = function(github) {
var html = '<div class="widget"><h2>GitHub Activity</h2><ul>';
var MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
for (var i=0; i<github.data.length; i++) {
var item = github.data[i];
var date = new Date(item.created_at);
var date_str = MONTHS[date.getMonth()] + ' ' + date.getDate();
var url = 'https://github.com/' + item.repo.name;
if (item.type === 'PushEvent') {
url += '/commit/' + item.payload.head;
}
var repo = '<a href="' + url + '" target="_blank">' + item.repo.name + '</a>';
if (item.type === 'CreateEvent') {
html += '<li>' + date_str + ': created ' + repo + '</li>';
} else if (item.type === 'PushEvent') {
html += '<li>' + date_str + ': pushed ' + item.payload.size + ' commit to ' + repo + '</li>';
}
}
html += '</ul></div>';
var el = document.createElement('div');
el.innerHTML = html;
document.getElementById('github-activity').appendChild(el);
};
gadgets.util.registerOnLoadHandler(function() {
var URL = 'https://api.github.com/users/' + prefs.getString('username') + '/events?callback=renderGitHubWidget';
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', URL);
document.head.appendChild(script);
});
</script>
]]>
</Content>
</Module>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment