var urlTemplate = "http://traduku.net/cgi-bin/traduku?en_eo=ubiquity&t=${words}"; CmdUtils.makeSearchCommand({ name: "traduku", author: { name: "Traduku.Net", email: "aaron4@lingvo.org"}, url: CmdUtils.renderTemplate(urlTemplate, {words: "{QUERY}"}), preview: function(pblock, args) { this.previewBlock = pblock; this._translate(args.text); }, description: "Translate words using lingvo.ru", help: "type lingvo or lingvo this to translate selection, type lingvo word to translate word", icon: "http://lingvo.ru/favicon.ico", _translate: function(words) { CmdUtils.log("translating " + words); this.previewBlock.innerHTML = "translating " + words + " ..."; if (this.oldRequest != undefined) { this.oldRequest.abort(); } var requestUrl = CmdUtils.renderTemplate(urlTemplate, {words: words.replace(/ /, "+")}); var self = this; this.oldRequest = jQuery.get(requestUrl, {}, function(data) { self._onTranslated(words, data); } ); }, _onTranslated: function(words, htmlResponse) { var response = this._findTranslateSection(htmlResponse); if (response == null) { this.previewBlock.innerHTML = "Could not translate \" " + words + " \""; } else { var self = this; jQuery("a", response).each( function(){this.href = "www.abbyyonline.ru/" + this.href;}); this.previewBlock.innerHTML = response.html(); } }, _findTranslateSection: function(htmlString){ var temp = this.previewBlock.cloneNode(false); temp.innerHTML = htmlString; var response = jQuery(temp).find("#MainSection"); if(response.length != 0){ return response; } response = jQuery(temp).find("#WordSection"); if(response.length != 0){ return response; } return null; } } );