Skip to content

Instantly share code, notes, and snippets.

@bitzesty
Created December 15, 2009 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bitzesty/257033 to your computer and use it in GitHub Desktop.
Save bitzesty/257033 to your computer and use it in GitHub Desktop.
talker plugin for formatting github repos
plugin.onMessageInsertion = function(event){
var github_status_expression = /https*:\/\/github.com\/(.*)\/(.*)/i;
var last_anchor = Talker.getLastInsertion().find('a');
var last_href = last_anchor.attr('href') || '';
if (github_status_expression.test(last_href)){
var author = last_href.match(github_status_expression)[1];
var repo = last_href.match(github_status_expression)[2];
var url = 'http://github.com/api/v2/json/repos/show/'+author+'/'+repo+'?callback=?';
if (last_anchor.hasClass('transformed')){
return true; // Do not transform the link a second time.
}
$.getJSON(url, function(data){
if (!last_anchor.hasClass('transformed')){
var repo = data.repository;
// todo some styling
var widget = "<li class=\"project\" style =\"background:none repeat scroll 0 0 #F5F5F5;border:1px solid #DDDDDD;list-style-type:none;padding:10px;width:60%;\">"+
"<ul class=\"repo-stats\" style=\"float:right;margin:0;\">"+
"<li style=\"display:inline;list-style-type:none;margin:0 0 0 2px;\">"+
"<a class=\"pill pill-watchers\" title=\"Watchers (click to see who is watching)\" style='-moz-border-radius:5px 5px 5px 5px;background:url(http://github.com/images/modules/buttons/pill_icon_matrix.gif) no-repeat scroll 5px 3px #FFFFFF;border:1px solid #DDDDDD; color:#666666;display:inline-block;font-size:10px;font-weight:bold;padding:1px 5px 1px 20px;' href=\"" + repo.url + "/watchers\">"+repo.watchers+"</a>"+
"</li>"+
"<li style=\"display:inline;list-style-type:none;margin:0 0 0 2px;\">"+
"<a class=\"pill pill-forks\" title=\"Forks (click to see network)\" style='-moz-border-radius:5px 5px 5px 5px;background:url(http://github.com/images/modules/buttons/pill_icon_matrix.gif) no-repeat scroll 5px -37px #FFFFFF;border:1px solid #DDDDDD; color:#666666;display:inline-block;font-size:10px;font-weight:bold;padding:1px 5px 1px 20px;' href=\"" + repo.url + "/network\">"+repo.forks+"</a>"+
"</li>"+
"</ul>"+
"<h3 style='font-size:14px;margin:0;'>"+ '<a href=\'' + repo.url + "\' style='color:#4183C4;text-decoration:none;'>"+repo.name+'</a>' + "</h3>"+
"<p style='color:#333333;font-size:12px;margin:2px 0 10px;'>"+repo.description+'</p>'+
"</li>"
last_anchor.html($('<q/>').css({
clear: 'both',
float: 'left'
})).append(widget).addClass('transformed'); // tag as tranformed so we don't do it again
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment