Created
December 10, 2013 14:09
-
-
Save mikedidthis/7891131 to your computer and use it in GitHub Desktop.
Parse Tumblr Tweets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<3 Thank you for this.