JSFiddle - React, Tailwind, and code Playground
HTML
<div id="target"></div>
JavaScript
( function( global )
{
var String, $;
if( global.jQuery )
{
String = global.String;
$ = window.jQuery;
String.prototype = $.extend( String.prototype, {
// Parse tweets for URLs and convert to links
parseURL: function()
{
return this.replace( /[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g, function( url )
{
return url.link( url );
} );
},
// Parse tweets for twitter usernames and convert to links
parseUsername: function()
{
return this.replace( /@[a-zA-Z0-9_.-]+\b/g, function( user )
{
return user.link( 'http://twitter.com/' + user.replace( '@', '' ) );
} );
},
// Parse tweets for hashtags and convert to links
parseHashtag: function()
{
return this.replace( /[#]+[A-Za-z0-9-_]+/g, function( hash )
{
return hash.link( 'http://search.twitter.com/search?q=' + hash.replace( '#', '%23' ) );
} );
}
} );
$.fn.tweetGet = function( options )
{
var defaults = {
query: 'from:ihatedjlex&rpp=10',
url: 'http://search.twitter.com/search.json?callback=?&q='
};
options = $.extend( defaults, options );
return this.each( function()
{
var target = this;
// Get tweets from user query
$.getJSON( options.url + options.query, function( data )
{
var tweets = [];
$.each( data.results, function( i, tweet )
{
tweets.push( '<li>' + tweet.text.parseURL().parseUsername().parseHashtag() + '</li>' );
} );
...