aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/api.js26
-rw-r--r--ext/bg/js/backend.js20
-rw-r--r--ext/bg/js/search-frontend.js3
-rw-r--r--ext/bg/js/search.js8
-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
-rw-r--r--ext/mixed/js/display.js9
9 files changed, 62 insertions, 44 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index b56b3449..0b80f099 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -17,16 +17,16 @@
*/
-function apiOptionsGetSync() {
+function apiOptionsGetSync(optionsContext) {
return utilBackend().options;
}
-async function apiOptionsGet() {
- return apiOptionsGetSync();
+async function apiOptionsGet(optionsContext) {
+ return apiOptionsGetSync(optionsContext);
}
-async function apiTermsFind(text) {
- const options = apiOptionsGetSync();
+async function apiTermsFind(text, optionsContext) {
+ const options = apiOptionsGetSync(optionsContext);
const translator = utilBackend().translator;
const searcher = {
@@ -48,14 +48,14 @@ async function apiTermsFind(text) {
};
}
-async function apiKanjiFind(text) {
- const options = apiOptionsGetSync();
+async function apiKanjiFind(text, optionsContext) {
+ const options = apiOptionsGetSync(optionsContext);
const definitions = await utilBackend().translator.findKanji(text, dictEnabledSet(options));
return definitions.slice(0, options.general.maxResults);
}
-async function apiDefinitionAdd(definition, mode, context) {
- const options = apiOptionsGetSync();
+async function apiDefinitionAdd(definition, mode, context, optionsContext) {
+ const options = apiOptionsGetSync(optionsContext);
if (mode !== 'kanji') {
await audioInject(
@@ -77,14 +77,15 @@ async function apiDefinitionAdd(definition, mode, context) {
return utilBackend().anki.addNote(note);
}
-async function apiDefinitionsAddable(definitions, modes) {
+async function apiDefinitionsAddable(definitions, modes, optionsContext) {
+ const options = apiOptionsGetSync(optionsContext);
const states = [];
try {
const notes = [];
for (const definition of definitions) {
for (const mode of modes) {
- const note = await dictNoteFormat(definition, mode, apiOptionsGetSync());
+ const note = await dictNoteFormat(definition, mode, options);
notes.push(note);
}
}
@@ -132,7 +133,8 @@ async function apiCommandExec(command) {
},
toggle: async () => {
- const options = apiOptionsGetSync();
+ const optionsContext = {depth: 0};
+ const options = apiOptionsGetSync(optionsContext);
options.general.enable = !options.general.enable;
await optionsSave(options);
}
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 0394c4ec..6afa9617 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -78,24 +78,24 @@ class Backend {
};
const handlers = {
- optionsGet: ({callback}) => {
- forward(apiOptionsGet(), callback);
+ optionsGet: ({optionsContext, callback}) => {
+ forward(apiOptionsGet(optionsContext), callback);
},
- kanjiFind: ({text, callback}) => {
- forward(apiKanjiFind(text), callback);
+ kanjiFind: ({text, optionsContext, callback}) => {
+ forward(apiKanjiFind(text, optionsContext), callback);
},
- termsFind: ({text, callback}) => {
- forward(apiTermsFind(text), callback);
+ termsFind: ({text, optionsContext, callback}) => {
+ forward(apiTermsFind(text, optionsContext), callback);
},
- definitionAdd: ({definition, mode, context, callback}) => {
- forward(apiDefinitionAdd(definition, mode, context), callback);
+ definitionAdd: ({definition, mode, context, optionsContext, callback}) => {
+ forward(apiDefinitionAdd(definition, mode, context, optionsContext), callback);
},
- definitionsAddable: ({definitions, modes, callback}) => {
- forward(apiDefinitionsAddable(definitions, modes), callback);
+ definitionsAddable: ({definitions, modes, optionsContext, callback}) => {
+ forward(apiDefinitionsAddable(definitions, modes, optionsContext), callback);
},
noteView: ({noteId}) => {
diff --git a/ext/bg/js/search-frontend.js b/ext/bg/js/search-frontend.js
index 840a1ea8..df5ccf81 100644
--- a/ext/bg/js/search-frontend.js
+++ b/ext/bg/js/search-frontend.js
@@ -18,7 +18,8 @@
async function searchFrontendSetup() {
- const options = await apiOptionsGet();
+ const optionsContext = {depth: 0};
+ const options = await apiOptionsGet(optionsContext);
if (!options.scanning.enableOnSearchPage) { return; }
const scriptSrcs = [
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index a3382398..6bdc47d8 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -21,6 +21,10 @@ class DisplaySearch extends Display {
constructor() {
super($('#spinner'), $('#content'));
+ this.optionsContext = {
+ depth: 0
+ };
+
this.search = $('#search').click(this.onSearch.bind(this));
this.query = $('#query').on('input', this.onSearchInput.bind(this));
this.intro = $('#intro');
@@ -46,8 +50,8 @@ class DisplaySearch extends Display {
try {
e.preventDefault();
this.intro.slideUp();
- const {length, definitions} = await apiTermsFind(this.query.val());
- super.termsShow(definitions, await apiOptionsGet());
+ const {length, definitions} = await apiTermsFind(this.query.val(), this.optionsContext);
+ super.termsShow(definitions, await apiOptionsGet(this.optionsContext));
} catch (e) {
this.onError(e);
}
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)) {
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index ebf56897..eca67b5e 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -27,6 +27,7 @@ class Display {
this.sequence = 0;
this.index = 0;
this.audioCache = {};
+ this.optionsContext = {};
this.dependencies = {};
@@ -66,7 +67,7 @@ class Display {
context.source.source = this.context.source;
}
- const kanjiDefs = await apiKanjiFind(link.text());
+ const kanjiDefs = await apiKanjiFind(link.text(), this.optionsContext);
this.kanjiShow(kanjiDefs, this.options, context);
} catch (e) {
this.onError(e);
@@ -89,7 +90,7 @@ class Display {
try {
textSource.setEndOffset(this.options.scanning.length);
- ({definitions, length} = await apiTermsFind(textSource.text()));
+ ({definitions, length} = await apiTermsFind(textSource.text(), this.optionsContext));
if (definitions.length === 0) {
return false;
}
@@ -379,7 +380,7 @@ class Display {
async adderButtonUpdate(modes, sequence) {
try {
- const states = await apiDefinitionsAddable(this.definitions, modes);
+ const states = await apiDefinitionsAddable(this.definitions, modes, this.optionsContext);
if (!states || sequence !== this.sequence) {
return;
}
@@ -453,7 +454,7 @@ class Display {
}
}
- const noteId = await apiDefinitionAdd(definition, mode, context);
+ const noteId = await apiDefinitionAdd(definition, mode, context, this.optionsContext);
if (noteId) {
const index = this.definitions.indexOf(definition);
Display.adderButtonFind(index, mode).addClass('disabled');