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.js27
1 files changed, 23 insertions, 4 deletions
diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js
index e7300874..14c0a95f 100644
--- a/ext/fg/js/client.js
+++ b/ext/fg/js/client.js
@@ -27,6 +27,7 @@ class Client {
this.enabled = false;
this.options = {};
this.definitions = null;
+ this.sequence = 0;
this.fgRoot = chrome.extension.getURL('fg');
chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this));
@@ -105,16 +106,21 @@ class Client {
if (length === 0) {
this.hidePopup();
} else {
+ const sequence = this.sequence++;
range.setLength(length);
bgRenderText(
- {defs: definitions, root: this.fgRoot, options: this.options},
+ {defs: definitions, root: this.fgRoot, options: this.options, sequence: sequence},
'term-list.html',
(content) => {
this.definitions = definitions;
this.showPopup(range, content);
+
bgCanAddNotes(definitions, (states) => {
if (states !== null) {
- states.forEach((state, index) => this.popup.sendMessage('setActionState', {index: index, state: state}));
+ states.forEach((state, index) => this.popup.sendMessage(
+ 'setActionState',
+ {index: index, state: state, sequence: sequence}
+ ));
}
});
}
@@ -127,17 +133,30 @@ class Client {
const state = {};
state[mode] = false;
- this.popup.sendMessage('setActionState', {index: index, state: state});
+ this.popup.sendMessage(
+ 'setActionState',
+ {index: index, state: state, sequence: this.sequence}
+ );
}
actionDisplayKanji(kanji) {
bgFindKanji(kanji, (definitions) => {
+ const sequence = this.sequence++;
bgRenderText(
- {defs: definitions, root: this.fgRoot, options: this.options},
+ {defs: definitions, root: this.fgRoot, options: this.options, sequence: sequence},
'kanji-list.html',
(content) => {
this.definitions = definitions;
this.popup.setContent(content, definitions);
+
+ bgCanAddNotes(definitions, (states) => {
+ if (states !== null) {
+ states.forEach((state, index) => this.popup.sendMessage(
+ 'setActionState',
+ {index: index, state: state, sequence: sequence}
+ ));
+ }
+ });
}
);
});