summaryrefslogtreecommitdiff
path: root/ext/fg/js/client.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fg/js/client.js')
-rw-r--r--ext/fg/js/client.js55
1 files changed, 13 insertions, 42 deletions
diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js
index 12b04066..aea2d607 100644
--- a/ext/fg/js/client.js
+++ b/ext/fg/js/client.js
@@ -26,8 +26,7 @@ class Client {
this.activateBtn = 2;
this.enabled = false;
this.options = {};
- this.results = null;
- this.xhr = null;
+ this.definitions = null;
this.fgRoot = chrome.extension.getURL('fg');
chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this));
@@ -102,17 +101,18 @@ class Client {
}
range.setLength(this.options.scanLength);
- findTerm(range.text(), ({results, length}) => {
+ findTerm(range.text(), ({definitions, length}) => {
if (length === 0) {
this.hidePopup();
} else {
range.setLength(length);
renderText(
- {defs: results, root: this.fgRoot, options: this.options},
+ {defs: definitions, root: this.fgRoot, options: this.options},
'term-list.html',
(content) => {
- this.results = results;
- this.showPopup(range, content, results);
+ this.definitions = definitions;
+ this.showPopup(range, content);
+ canAddNotes(definitions, (states) => this.popup.sendMessage('setActionStates', states));
}
);
}
@@ -120,23 +120,17 @@ class Client {
}
actionAddNote(mode, index, callback) {
- callback({
- action: 'disableAction',
- params: {
- mode: mode,
- index: index
- }
- });
+
}
actionDisplayKanji(kanji) {
- findKanji(kanji, (results) => {
+ findKanji(kanji, (definitions) => {
renderText(
- {defs: results, root: this.fgRoot, options: this.options},
+ {defs: definitions, root: this.fgRoot, options: this.options},
'kanji-list.html',
(content) => {
- this.results = results;
- this.popup.setContent(content, results);
+ this.definitions = definitions;
+ this.popup.setContent(content, definitions);
}
);
});
@@ -159,8 +153,8 @@ class Client {
this.lastRange.deselect();
}
- this.lastRange = null;
- this.results = null;
+ this.lastRange = null;
+ this.definitions = null;
}
setEnabled(enabled) {
@@ -172,29 +166,6 @@ class Client {
setOptions(opts) {
this.options = opts;
}
-
- callAnkiApi(action, params, callback) {
- if (!this.options.enableAnkiConnect) {
- callback(null);
- return;
- }
-
- if (this.xhr !== null) {
- this.xhr.abort();
- }
-
- this.xhr = new XMLHttpRequest();
- this.xhr.addEventListener('loadend', () => {
- const resp = this.xhr.responseText;
- callback(resp ? JSON.parse(resp) : null);
- this.xhr = null;
- });
-
- this.xhr.open('POST', 'http://127.0.0.1:8888');
- this.xhr.withCredentials = true;
- this.xhr.setRequestHeader('Content-Type', 'text/json');
- this.xhr.send(JSON.stringify({action: action, params: params}));
- }
}
window.yomiClient = new Client();