Simplified this some more, I wasn't crazy about the previous solution:
Code:
var params = $("#tweets").attr("rel").split("|"),
username = params[0],
count = params[1],
url = 'http://api.twitter.com/1/statuses/user_timeline/' + username + '.json?callback=?';
$.getJSON(url, function(tweet) {
var i, tweets,
atNamePattern = /@[\w-]+/,
atSearchPattern = /#[\w-]+/,
// Modified from http://stackoverflow.com/questions/37684/how-to-replace-plain-urls-with-links/7138764#7138764
urlPattern = /\b(?:https?):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim;
tweets += '<ul>';
for (i = 0; i <= count; i++) {
tweet[i].text = tweet[i].text
.replace(urlPattern, '<a href="$&">$&</a>')
.replace(atNamePattern, '<a href="http://twitter.com/$&">$&</a>')
.replace(atSearchPattern, '<a href="http://twitter.com/search?q=$&">$&</a>');
tweets += '<li class="tweet">' + (tweet[i].text) + '</li>';
}
tweets += '</ul>';
$("#tweets").html(tweets);
});
Bookmarks