Created
January 24, 2010 14:29
-
-
Save tiff/285223 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* 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