From 57a426f4f277d1e5dac98b0427efcb43f5ab20e4 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 2 May 2016 20:40:41 -0700 Subject: Plumbing --- ext/bg/js/yomichan.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index a412eef7..32c12407 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -101,15 +101,23 @@ class Yomichan { findTerm(text, callback) { const results = this.translator.findTerm(text); - this.callAnkiApi('canAddNotes', results, (resultsFull) => { - callback(resultsFull || results); + this.callAnkiApi('canAddNotes', results.results, (definitions) => { + if (definitions !== null) { + results.results = definitions; + } + + callback(results); }); } findKanji(text, callback) { const results = this.translator.findKanji(text); - this.callAnkiApi('cannAddNotes', results, (resultsFull) => { - callback(resultsFull || results); + this.callAnkiApi('cannAddNotes', results.results, (definitions) => { + if (definitions !== null) { + results.results = definitions; + } + + callback(results); }); } @@ -120,7 +128,7 @@ class Yomichan { xhr.open('POST', 'http://127.0.0.1:8888'); xhr.withCredentials = true; xhr.setRequestHeader('Content-Type', 'text/json'); - xhr.send(JSON.stringify(data)); + xhr.send(JSON.stringify({action: action, data: data})); } else { callback(null); } -- cgit v1.2.3