JSFiddle - React, Tailwind, and code Playground
by Eric Hynds
HTML
<div id="status"></div>
JavaScript
// http://www.dustindiaz.com/async-method-queues/
function fetchTweet(url) {
this.q = $({});
this.tweet = "";
var self = this;
$.getJSON(url, function(resp) {
self.tweet = resp.results[0].text;
self.q.dequeue('tweet');
});
}
fetchTweet.prototype = {
linkify: function() {
var self = this;
this.q.queue('tweet', function(next) {
self.tweet = self.tweet.replace(/(@\w{1,20})\b/g, '<a href="...">$1</a>');
next();
});
return this;
},
filterBadWords: function(next) {
var self = this;
this.q.queue('tweet', function(next) {
self.tweet = self.tweet.replace(/\b(fuck|shit|piss)\b/g, "");
next();
});
return this;
},
appendTo: function(selector) {
var self = this;
this.q.queue('tweet', function(next) {
$('<p>', { html: self.tweet }).appendTo(selector);
next();
});
return this;
}
};
new fetchTweet('http://search.twitter.com/search.json?q=omg&rpp=1&callback=?').linkify().filterBadWords().appendTo('#status');