diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-11-28 15:18:27 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-12-29 12:33:15 -0500 |
commit | 50e0fbbb662230a3a9f6e7354c229200bd1a03a2 (patch) | |
tree | 033ffdf6c4ab75d6c44f6a25c2ed5629f8f3cf99 /ext/bg | |
parent | b770944b127a8b549b94f6ba2b038917acd63eff (diff) |
Use schema to validate options
Diffstat (limited to 'ext/bg')
-rw-r--r-- | ext/bg/background.html | 1 | ||||
-rw-r--r-- | ext/bg/js/backend.js | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/ext/bg/background.html b/ext/bg/background.html index 4c6f8795..af87eddb 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -31,6 +31,7 @@ <script src="/bg/js/deinflector.js"></script> <script src="/bg/js/dictionary.js"></script> <script src="/bg/js/handlebars.js"></script> + <script src="/bg/js/json-schema.js"></script> <script src="/bg/js/options.js"></script> <script src="/bg/js/profile-conditions.js"></script> <script src="/bg/js/request.js"></script> diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 1a874dc8..55841cd6 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -23,6 +23,7 @@ class Backend { this.anki = new AnkiNull(); this.mecab = new Mecab(); this.options = null; + this.optionsSchema = null; this.optionsContext = { depth: 0, url: window.location.href @@ -38,7 +39,16 @@ class Backend { async prepare() { await this.translator.prepare(); + + this.optionsSchema = await requestJson(chrome.runtime.getURL('/bg/data/options-schema.json'), 'GET'); this.options = await optionsLoad(); + try { + this.options = JsonSchema.getValidValueOrDefault(this.optionsSchema, this.options); + } catch (e) { + // This shouldn't happen, but catch errors just in case of bugs + logError(e); + } + this.onOptionsUpdated('background'); if (chrome.commands !== null && typeof chrome.commands === 'object') { |