/ Published in: JavaScript
Expand |
Embed | Plain Text
function getTweets(handle, tweetHash) { // Create a ul for the Twitter statuses: var twitter_nod = jQuery('<ul id="twitter-feed"></ul>').insertAfter("#tweets"); var maxTweets = 3; // Get & parse json object: var JSONCallback = function(data) { var html = ''; var count = 0; $.each(data, function(i,item) { var content_str = item.text; var content_created = item.created_at; if (item.text.toLowerCase().indexOf(tweetHash) === -1 || count > maxTweets) { return true; /*continue*/ } content_str = content_str.replace(/http:\/\/\S+/g, '<a href="$&" class="external" rel="nofollow">$&</a>'); content_str = content_str.replace(/(@)(\w+)/g, ' @<a href="http://twitter.com/$2" class="external" rel="nofollow">$2</a>'); content_str = content_str.replace(/(#)(\w+)/g, ' #<a href="http://search.twitter.com/search?q=%23$2" class="external" rel="nofollow">$2</a>'); //evenOdd_str = i % 2 == 0 ? 'odd' : 'even'; //$("#twitter-feed").append('<li class="'+evenOdd_str+'">'+content_str +'</li>'); html += '<p>' + content_str + '<span id="tweet-date">' + calcTime(content_created) + '</span></p>'; count++; }); var $tweets = $("#tweets"); if (html == '') { html = '<p>There are no tweets.</p>'; } $tweets.append(html); }; $.getJSON("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=" + handle + "&count=200&callback=?",JSONCallback); }
You need to login to post a comment.
