Skip to content

Instantly share code, notes, and snippets.

@jcontonio
Created April 23, 2010 15:13
Show Gist options
  • Select an option

  • Save jcontonio/376651 to your computer and use it in GitHub Desktop.

Select an option

Save jcontonio/376651 to your computer and use it in GitHub Desktop.
Javascript Twitter Statuses
/*------------------------------------------------------------------
Author: Jay Contonio - http://jcontonio.com/
Last change: 2009-03-13
Requires: jQuery
-------------------------------------------------------------------*/
// The username for the twitter feed
var user = "TWITTER_USERNAME";
// All our twitter data gets loaded into this array
var twitterData = new Array();
// This is the current piece of data we're looking at
var currentTwit = 0;
// This is the maximum number of tweets to load
var maxTwit = 1;
function loadTwitterData()
{
var url = "http://twitter.com/status/user_timeline/" + user + ".json?limit=" + maxTwit + "&callback=?";
$.getJSON(url,
function(data){
$.each(data, function(i, item) {
insertIntoArray(item.text.linkify());
if(i == maxTwit) {
return false;
}
})
});
}
function insertIntoArray(data)
{
twitterData.push(data);
if(twitterData.length == maxTwit) {
showData(currentTwit);
}
}
function showData(item)
{
$("#twitter > p").html(twitterData[item]);
}
String.prototype.linkify = function()
{
return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
return m.link(m);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment