Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.