Last active
August 7, 2016 12:38
-
-
Save mindplay-dk/5232784 to your computer and use it in GitHub Desktop.
GitHub Gadget for Blogger
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
<?xml version="1.0" encoding="UTF-8" ?> | |
<Module> | |
<ModulePrefs title="GitHub Activity" /> | |
<UserPref name="username" display_name="GitHub Username" 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> |
Good try... it is not working for me one year later.... nevermind... thx for your work
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Both Google Gadget Editor and Validator appear to be dead - in the end, I gave up, pasted my code directly into a custom HTML gadget, which worked perfectly.