-
-
Save inothilmi/4fa5d26c80b199826bf2c48d16a30bf7 to your computer and use it in GitHub Desktop.
Revisions
-
SelmanH revised this gist
Oct 14, 2013 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -12,10 +12,9 @@ function getMean(word){ res = JSON.parse( massaged ); } catch( e ) { res = new Function( 'return ' + massaged )(); } $('#result').val(process(res)); } } -
SelmanH revised this gist
Oct 14, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -12,10 +12,10 @@ function getMean(word){ res = JSON.parse( massaged ); } catch( e ) { res = new Function( 'return ' + massaged )(); $('#result').val(res); } $('#result').val(res); } } -
SelmanH revised this gist
Oct 14, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ function getMean(word){ ajax = new XMLHttpRequest(); // result callback ajax.onreadystatechange = function(){ if(ajax.readyState==4 && ajax.status==200){ var massaged = ajax.responseText.replace(/^[^(]+\(|[^}]+$/g, ''), res; -
SelmanH revised this gist
Oct 14, 2013 . 1 changed file with 9 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,28 +1,25 @@ function getMean(word){ if(word==""|| word=="Enter a word") return; ajax = new XMLHttpRequest(); // result ajax.onreadystatechange = function(){ if(ajax.readyState==4 && ajax.status==200){ var massaged = ajax.responseText.replace(/^[^(]+\(|[^}]+$/g, ''), res; try { res = JSON.parse( massaged ); } catch( e ) { res = new Function( 'return ' + massaged )(); return res; } return res; } } // make the call var encoded = encodeURIComponent("http://www.google.com/dictionary/json?callback=process&sl=en&tl=en&restrict=pr,de&client=te&q=" + word); ajax.open("GET","proxy.php?url=" + encoded,true); ajax.send(null); -
SelmanH created this gist
Oct 14, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,79 @@ function getMean(word){ if(word==""|| word=="Enter a word") return; ajax = new XMLHttpRequest(); // result ajax.onreadystatechange = function(){ if(ajax.readyState==4 && ajax.status==200){ var massaged = ajax.responseText.replace(/^[^(]+\(|[^}]+$/g, ''), res; try { res = JSON.parse( massaged ); } catch( e ) { res = new Function( 'return ' + massaged )(); return res; } return res; } else{ document.getElementsByTagName("div")[1].innerHTML="<h3 class=\"loading\">Loading</h3>"; } } // make the call var encoded = encodeURIComponent("http://www.google.com/dictionary/json?callback=process&sl=en&tl=en&restrict=pr,de&client=te&q=" + word); ajax.open("GET","proxy.php?url=" + encoded,true); ajax.send(null); } // iterates through json result object, returns word definition object function process(json_obj){ var result = { sound : null, pronunciation : null, primary_means : null }; for (var prop in json_obj){ if(prop=="primaries"){ var stuff = json_obj["primaries"][0]; // get pronunciation and sound var isa = ""; var sound; var pro = stuff["terms"]; for(var i=0;i<pro.length;i++){ if(pro[i]["type"]=="phonetic"){ isa+=pro[i]["text"]; isa+=" "; } else if(pro[i]["type"]=="sound"){ sound = pro[i]["text"]; } } result.sound = sound; result.pronunciation = isa; // get meaning array var primary_mean = stuff["entries"]; var primary_mean_list = []; var k=0; for(var i=0;i<primary_mean.length;i++){ if(primary_mean[i]["type"]=="meaning"){ primary_mean_list[k]=primary_mean[i]["terms"][0]["text"]; k++; } } result.primary_means = primary_mean_list; } else continue; } return result; } var result = getMean('Philodendron'); console.log(result);