Skip to content

Instantly share code, notes, and snippets.

@Chrisedmo
Created October 30, 2012 11:16
Show Gist options
  • Save Chrisedmo/3979662 to your computer and use it in GitHub Desktop.
Save Chrisedmo/3979662 to your computer and use it in GitHub Desktop.
Quick JS tweets for static site.
$(document).ready(function () {
// Type in your twitter id here
var user = 'TWITTERID';
// How many Tweets do you want to display?
//Type in the number after &count=
// Do you wanna show RT's? include_rts= '0 for no' or '1 for yes'
$.getJSON('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' + user + '&count=3&include_rts=1&callback=?', function(data) {
var tweet = "";
for (i = 0; i < data.length; i++) {
tweet += data[i].text + "</br></br>";
}
tweet = tweet.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, function(url) {
return '<a target="_blank" href="'+url+'">'+url+'</a>';
}).replace(/B@([_a-z0-9]+)/ig, function(reply) {
return reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
});
// Give your tweets a home: here an element of id tweet (#tweet)
$("#tweet").html(tweet);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment