Skip to content

Instantly share code, notes, and snippets.

@garyharan
Forked from bitzesty/github-repos-talker-plugin.js
Created December 15, 2009 17:13
Show Gist options
  • Save garyharan/257100 to your computer and use it in GitHub Desktop.
Save garyharan/257100 to your computer and use it in GitHub Desktop.
plugin.onMessageInsertion = function(event){
// regex is probably wrong
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];
console.log(author);
console.log(repo);
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 = '<a href=' + repo.url + '>'+repo.name+'</a>'+'<p>'+repo.description+'</p>'+'<p>'+'<span=\'watchers\'>'+repo.watchers+'</span>'+'</p>';
last_anchor.html($('<q/>').css({
clear: 'both',
float: 'left'
}).append(
$('<div>').attr({'class': 'github-repo'}).append(widget)
).addClass('transformed'); // tag as tranformed so we don't do it again
}
});
}
}
// syntax error somewhere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment