Skip to content

Instantly share code, notes, and snippets.

@mikedidthis
Created December 10, 2013 14:09
Show Gist options
  • Save mikedidthis/7891131 to your computer and use it in GitHub Desktop.
Save mikedidthis/7891131 to your computer and use it in GitHub Desktop.
Parse Tumblr Tweets
function parseTweet(text) {
var patterns = {
link: /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig,
user: /(^|\s)@(\w+)/g,
hash: /(^|\s)#(\w+)/g
};
return text.replace(patterns.link,'<a href="$1" target="_blank">$1</a>')
.replace(patterns.user, '$1@<a href="http://www.twitter.com/$2" target="_blank">$2</a>')
.replace(patterns.hash, '$1#<a href="http://search.twitter.com/search?q=%23$2" target="_blank">$2</a>');
}
function recent_tweets(data) {
for (i=0; i<data.length; i++) {
document.getElementById("tweets").innerHTML =
document.getElementById("tweets").innerHTML +
'<div>' + parseTweet(data[i].text) + '</div>';
}
document.getElementById("twitter").style.display = 'block';
}
@ara303
Copy link

ara303 commented Dec 11, 2013

<3 Thank you for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment