Skip to content

Instantly share code, notes, and snippets.

@mikedidthis
Created December 10, 2013 14:09
Show Gist options
  • Select an option

  • Save mikedidthis/7891131 to your computer and use it in GitHub Desktop.

Select an option

Save mikedidthis/7891131 to your computer and use it in GitHub Desktop.

Revisions

  1. mikedidthis created this gist Dec 10, 2013.
    18 changes: 18 additions & 0 deletions tweets.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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';
    }