Skip to content

Instantly share code, notes, and snippets.

@tiff
Created January 24, 2010 14:29
Show Gist options
  • Save tiff/285223 to your computer and use it in GitHub Desktop.
Save tiff/285223 to your computer and use it in GitHub Desktop.
/**
* toLolcatString()
* Converts a string from plain english to lolcat speak using YQL and jQuery
*
* @example
* toLolcatString("Hi. How are you?", function(lolcatStr) { alert(lolcatStr); }); // => "OH HAI. HOWZ U?"
*/
var toLolcatString = (function() {
var YQL_QUERY = "SELECT content FROM html WHERE url=\"http://speaklolcat.com/?from={str}\" AND xpath='//textarea[@id=\"to\"]'";
return function(str, callback) {
var encodedStr = encodeURIComponent(str),
query = YQL_QUERY.replace("{str}", encodedStr);
$.getJSON("http://query.yahooapis.com/v1/public/yql?format=json&callback=?", {
q: query
}, function(response) {
var lolcatStr = response && response.query && response.query.results && response.query.results.textarea;
if (typeof(lolcatStr) != "undefined") {
callback(lolcatStr);
}
});
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment