diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-09-07 13:58:19 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-09-10 20:09:33 -0400 |
commit | bc8793eb56b2ce985f2e5dc0a9fd270f98fbf17a (patch) | |
tree | b390bf63356b1584ea6d9bb5ff98450d96fb0e04 /ext/bg/js/api.js | |
parent | 99ca60d4c1456f243d8142b4502db441e33340a4 (diff) |
Add a context object for all calls to fetch options
Diffstat (limited to 'ext/bg/js/api.js')
-rw-r--r-- | ext/bg/js/api.js | 26 |
1 files changed, 14 insertions, 12 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); } |