summaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-03-01 14:41:48 -0500
committerGitHub <noreply@github.com>2020-03-01 14:41:48 -0500
commita4b0a556d48f2b0ae4208f69fa651d2370529db5 (patch)
tree5a304f9be64829e07d311bbf51871aeda28fe10b /ext/bg/js/backend.js
parent7c615244f40222584984157223944e6aa6448d13 (diff)
parent8e29da0c6bd0b80dc6c9e37a525a37258518c293 (diff)
Merge pull request #380 from toasted-nutbread/anki-templates-file
Load default Anki field templates from a file
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js20
1 files changed, 11 insertions, 9 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 238ac52c..b99d1ca4 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -17,7 +17,7 @@
*/
/*global optionsSave, utilIsolate
-conditionsTestValue, profileConditionsDescriptor, profileOptionsGetDefaultFieldTemplates
+conditionsTestValue, profileConditionsDescriptor
handlebarsRenderDynamic
requestText, requestJson, optionsLoad
dictConfigured, dictTermsSort, dictEnabledSet, dictNoteFormat
@@ -33,6 +33,7 @@ class Backend {
this.clipboardMonitor = new ClipboardMonitor();
this.options = null;
this.optionsSchema = null;
+ this.defaultAnkiFieldTemplates = null;
this.optionsContext = {
depth: 0,
url: window.location.href
@@ -74,7 +75,8 @@ class Backend {
['getDisplayTemplatesHtml', this._onApiGetDisplayTemplatesHtml.bind(this)],
['getQueryParserTemplatesHtml', this._onApiGetQueryParserTemplatesHtml.bind(this)],
['getZoom', this._onApiGetZoom.bind(this)],
- ['getMessageToken', this._onApiGetMessageToken.bind(this)]
+ ['getMessageToken', this._onApiGetMessageToken.bind(this)],
+ ['getDefaultAnkiFieldTemplates', this._onApiGetDefaultAnkiFieldTemplates.bind(this)]
]);
this._commandHandlers = new Map([
@@ -89,6 +91,7 @@ class Backend {
await this.translator.prepare();
this.optionsSchema = await requestJson(chrome.runtime.getURL('/bg/data/options-schema.json'), 'GET');
+ this.defaultAnkiFieldTemplates = await requestText(chrome.runtime.getURL('/bg/data/default-anki-field-templates.handlebars'), 'GET');
this.options = await optionsLoad();
try {
this.options = JsonSchema.getValidValueOrDefault(this.optionsSchema, this.options);
@@ -423,7 +426,7 @@ class Backend {
async _onApiDefinitionAdd({definition, mode, context, optionsContext}) {
const options = await this.getOptions(optionsContext);
- const templates = Backend._getTemplates(options);
+ const templates = this.defaultAnkiFieldTemplates;
if (mode !== 'kanji') {
await audioInject(
@@ -448,7 +451,7 @@ class Backend {
async _onApiDefinitionsAddable({definitions, modes, optionsContext}) {
const options = await this.getOptions(optionsContext);
- const templates = Backend._getTemplates(options);
+ const templates = this.defaultAnkiFieldTemplates;
const states = [];
try {
@@ -656,6 +659,10 @@ class Backend {
return this.messageToken;
}
+ async _onApiGetDefaultAnkiFieldTemplates() {
+ return this.defaultAnkiFieldTemplates;
+ }
+
// Command handlers
async _onCommandSearch(params) {
@@ -896,11 +903,6 @@ class Backend {
return 'chrome';
}
}
-
- static _getTemplates(options) {
- const templates = options.anki.fieldTemplates;
- return typeof templates === 'string' ? templates : profileOptionsGetDefaultFieldTemplates();
- }
}
window.yomichanBackend = new Backend();