Skip to content

Instantly share code, notes, and snippets.

@DavidQL
Created July 6, 2011 23:13
Show Gist options
  • Save DavidQL/1068563 to your computer and use it in GitHub Desktop.
Save DavidQL/1068563 to your computer and use it in GitHub Desktop.
replaceWord: ->
text = $( '#textarea' ).val().split(' ')
word = text[text.length-2]
index = text.length - 2
ajax =
url: 'http://words.bighugelabs.com/api/2/d60ba0946e7215aa09a94b94a20b4bbf/' + word + '/json'
type: 'GET'
dataType: 'jsonp'
success: ( data ) ->
text = $( '#textarea' ).val().split(' ')
if data.adjective? && data.adjective.syn[0]?
new_word = data.adjective.syn[0]
else if data.noun? && data.noun.syn[0]?
new_word = data.noun.syn[0]
text[text.length-2] = new_word
text = text.join ' '
$( '#textarea' ).val text
$.ajax ajax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment