Skip to content

Instantly share code, notes, and snippets.

@mwisnicki
Created February 16, 2011 00:37
Show Gist options
  • Save mwisnicki/828612 to your computer and use it in GitHub Desktop.
Save mwisnicki/828612 to your computer and use it in GitHub Desktop.
github gadget
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs directory_title="GitHub Repositories"
title="__UP_username__`s GitHub Repositories"
description="Shows a GitHub user's repositories."
author="Aupajo"
author_email="pete@metanation.com"
height="60"
screenshot="http://labs.metanation.com/github-google-gadget/screenshot.gif"
thumbnail="http://labs.metanation.com/github-google-gadget/logo.gif">
<Require feature="dynamic-height"/>
</ModulePrefs>
<UserPref name="username" required="true" datatype="string" display_name="Account Name" />
<UserPref display_name="Show" name="display_limit" default_value="10" datatype="enum">
<EnumValue value="5" />
<EnumValue value="10" />
<EnumValue value="15" />
<EnumValue value="20" />
<EnumValue value="50" />
</UserPref>
<Content type="html">
<![CDATA[
<style type="text/css">
body { background: transparent; }
a { color: #b5b5b5; text-decoration: none; }
a:link, a:visited { color: #b5b5b5; }
a:hover { text-decoration: underline; }
#content {
font-size: 0.8em;
padding: 0.5em 0;
}
#content a.repository {
background: url('https://raw.github.com/gist/828612/public.png') no-repeat 4px 50%;
display: block;
font-weight: bold;
margin-bottom: 2px;
padding: 4px 4px 4px 24px;
}
#content a.repository:hover { text-decoration: underline; }
#header {
color: #444;
padding: 0 0.5em 0.5em;
}
#footer {
color: #b5b5b5;
font-size: 0.9em;
margin-top: 0.5em;
text-align: right;
}
</style>
<div id="content">Loading&hellip;</div>
<script type="text/javascript">
function makeJSONRequest() {
updateContent("Attempting to retrieve account information&hellip;");
var params = {};
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
var prefs = new gadgets.Prefs();
var url = "https://api.github.com/users/" + gadgets.util.escapeString(prefs.getString('username')) + "/repos";
gadgets.io.makeRequest(url, response, params);
};
function updateContent(html) {
document.getElementById('content').innerHTML = html;
gadgets.window.adjustHeight();
}
function response(obj) {
var jsondata = obj.data;
if(jsondata.length > 0) {
var prefs = new gadgets.Prefs();
var limit = parseInt(prefs.getString('display_limit'));
var repos = jsondata;
var html = "";
for(var i = 0; i < repos.slice(0, limit).length; i++) {
html += '<a href="' + repos[i]['url'] + '" target="_blank" class="repository">' + repos[i]['name'] + '</a>';
}
html += '<div id="footer">';
html += '<a href="http://github.com/' + prefs.getString('username') + '" target="_blank">See All &raquo;</a>';
html += '</div>';
updateContent(html);
} else {
updateContent('No public repositories found for <b>' + gadgets.util.escapeString(prefs.getString('username')) + '</b>.');
}
}
gadgets.util.registerOnLoadHandler(makeJSONRequest);
</script>
]]>
</Content>
</Module>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment