Navigation

Saturday, May 15, 2010

Custom Twitter Callback

The source to my basic, yet slightly enhanced Twitter Callback for Blogger or any page really :)

My Enhancements include:
  1. #hashtag link creation
  2. In Reply To support (shows who I'm replying to and a link to their status like twitter.com)
  3. via support (again like twitter.com, shows from what client I posted)

function twitterCallback(twitters) {
var statusHTML = [];
for (var i=0; i<twitters.length; i++){
var username = twitters[i].user.screen_name;
var source = twitters[i].source;
var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
return ''+url+'';
}).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
return  reply.charAt(0)+''+reply.substring(1)+'';
}).replace(/\B#([_a-z0-9]+)/ig, function(hashtag) {
return ''+hashtag+'';
});

if (twitters[i].in_reply_to_screen_name != null) {
var replyto = twitters[i].in_reply_to_screen_name;
var replystatus = twitters[i].in_reply_to_status_id;
var inreplyto = 'in reply to '+replyto+'';
} else {
var inreplyto = '';
}
statusHTML.push('
  • '+username+' '+status+' '+relative_time(twitters[i].created_at)+' via '+source+' '+inreplyto+'
  • '); } document.getElementById('twitter_update_list').innerHTML = statusHTML.join(''); } ]]>

    No comments:

    Post a Comment