//* comment *// Copyright (C) 2015 Daksh Shah Copyright (C) 2016 Tymon Radzik This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . //* block:dictionary *// var dictionaryBlk = new ProtoBlock('dictionary'); dictionaryBlk.palette = palettes.dict['external']; blocks.protoBlockDict['dictionary'] = dictionaryBlk; dictionaryBlk.staticLabels.push(_('define')); dictionaryBlk.adjustWidthToLabel(); dictionaryBlk.oneArgMathBlock(); dictionaryBlk.dockTypes[1] = 'anyin'; dictionaryBlk.defaults.push('programming'); //* arg:dictionary *// var block = logo.blocks.blockList[blk]; var conns = block.connections; var word = (logo.parseArg(logo, turtle, conns[1])).toLowerCase(); var apiURL = "http://api.pearson.com/v2/dictionaries/entries?headword=" + word; var request = new XMLHttpRequest(); request.open('GET', apiURL, false); request.send(null); var response = request.responseText; var results = (JSON.parse(response))['results']; mainLoop: for (var i = 0; i < results.length; i++) { if (results[i].hasOwnProperty('senses')) { var result_senses = results[i].senses; for (var j = 0; j < result_senses.length; j++) { if (result_senses[j].hasOwnProperty('subsenses')) { if(result_senses[j].subsenses[0].hasOwnProperty('definition')) { block.value = result_senses[j].subsenses[0].definition; break mainLoop; } } if (result_senses[j].hasOwnProperty('definition')) { block.value = result_senses[j].definition; break mainLoop; } } } block.value = null; } //* palette-icon:external *// //* palette-fill:external *// #59f //* palette-stroke:external *// #3771c8 //* palette-highlight:external *// #9DC4FF //* palette-stroke-highlight:external *// #000000