summaryrefslogtreecommitdiff
path: root/ext/fg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-07 13:58:19 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-10 20:09:33 -0400
commitbc8793eb56b2ce985f2e5dc0a9fd270f98fbf17a (patch)
treeb390bf63356b1584ea6d9bb5ff98450d96fb0e04 /ext/fg
parent99ca60d4c1456f243d8142b4502db441e33340a4 (diff)
Add a context object for all calls to fetch options
Diffstat (limited to 'ext/fg')
-rw-r--r--ext/fg/js/api.js20
-rw-r--r--ext/fg/js/float.js5
-rw-r--r--ext/fg/js/frontend.js12
-rw-r--r--ext/fg/js/popup-nested.js3
4 files changed, 25 insertions, 15 deletions
diff --git a/ext/fg/js/api.js b/ext/fg/js/api.js
index aa3b2629..d0ac649a 100644
--- a/ext/fg/js/api.js
+++ b/ext/fg/js/api.js
@@ -17,24 +17,24 @@
*/
-function apiOptionsGet() {
- return utilInvoke('optionsGet');
+function apiOptionsGet(optionsContext) {
+ return utilInvoke('optionsGet', {optionsContext});
}
-function apiTermsFind(text) {
- return utilInvoke('termsFind', {text});
+function apiTermsFind(text, optionsContext) {
+ return utilInvoke('termsFind', {text, optionsContext});
}
-function apiKanjiFind(text) {
- return utilInvoke('kanjiFind', {text});
+function apiKanjiFind(text, optionsContext) {
+ return utilInvoke('kanjiFind', {text, optionsContext});
}
-function apiDefinitionAdd(definition, mode, context) {
- return utilInvoke('definitionAdd', {definition, mode, context});
+function apiDefinitionAdd(definition, mode, context, optionsContext) {
+ return utilInvoke('definitionAdd', {definition, mode, context, optionsContext});
}
-function apiDefinitionsAddable(definitions, modes) {
- return utilInvoke('definitionsAddable', {definitions, modes}).catch(() => null);
+function apiDefinitionsAddable(definitions, modes, optionsContext) {
+ return utilInvoke('definitionsAddable', {definitions, modes, optionsContext}).catch(() => null);
}
function apiNoteView(noteId) {
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js
index 3c521714..348c114e 100644
--- a/ext/fg/js/float.js
+++ b/ext/fg/js/float.js
@@ -23,6 +23,10 @@ class DisplayFloat extends Display {
this.autoPlayAudioTimer = null;
this.styleNode = null;
+ this.optionsContext = {
+ depth: 0
+ };
+
this.dependencies = Object.assign({}, this.dependencies, {docRangeFromPoint, docSentenceExtract});
$(window).on('message', utilAsync(this.onMessage.bind(this)));
@@ -75,6 +79,7 @@ class DisplayFloat extends Display {
},
popupNestedInitialize: ({id, depth, parentFrameId}) => {
+ this.optionsContext.depth = depth;
popupNestedInitialize(id, depth, parentFrameId);
}
};
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 5e12d101..0b60aa2b 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -28,6 +28,10 @@ class Frontend {
this.options = null;
this.ignoreNodes = (Array.isArray(ignoreNodes) && ignoreNodes.length > 0 ? ignoreNodes.join(',') : null);
+ this.optionsContext = {
+ depth: popup.depth
+ };
+
this.primaryTouchIdentifier = null;
this.contextMenuChecking = false;
this.contextMenuPrevent = false;
@@ -50,7 +54,7 @@ class Frontend {
async prepare() {
try {
- this.options = await apiOptionsGet();
+ this.options = await apiOptionsGet(this.optionsContext);
window.addEventListener('message', this.onFrameMessage.bind(this));
window.addEventListener('mousedown', this.onMouseDown.bind(this));
@@ -282,7 +286,7 @@ class Frontend {
}
async updateOptions() {
- this.options = await apiOptionsGet();
+ this.options = await apiOptionsGet(this.optionsContext);
if (!this.options.enable) {
this.searchClear();
}
@@ -351,7 +355,7 @@ class Frontend {
return;
}
- const {definitions, length} = await apiTermsFind(searchText);
+ const {definitions, length} = await apiTermsFind(searchText, this.optionsContext);
if (definitions.length === 0) {
return false;
}
@@ -384,7 +388,7 @@ class Frontend {
return;
}
- const definitions = await apiKanjiFind(searchText);
+ const definitions = await apiKanjiFind(searchText, this.optionsContext);
if (definitions.length === 0) {
return false;
}
diff --git a/ext/fg/js/popup-nested.js b/ext/fg/js/popup-nested.js
index e0376bb2..de2acccc 100644
--- a/ext/fg/js/popup-nested.js
+++ b/ext/fg/js/popup-nested.js
@@ -25,7 +25,8 @@ async function popupNestedInitialize(id, depth, parentFrameId) {
}
popupNestedInitialized = true;
- const options = await apiOptionsGet();
+ const optionsContext = {depth};
+ const options = await apiOptionsGet(optionsContext);
const popupNestingMaxDepth = options.scanning.popupNestingMaxDepth;
if (!(typeof popupNestingMaxDepth === 'number' && typeof depth === 'number' && depth < popupNestingMaxDepth)) {