diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-02-08 17:52:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-08 17:52:46 -0500 |
commit | 4b6703114c3fedaaf24cc7a376d885e22dfdc4f3 (patch) | |
tree | 5065ab70a1e56ee6187aeb9af46491ab1667b524 /ext/bg/js/context-main.js | |
parent | 849e4fabe1dffc2851fcb338dae8400d6c8e46ca (diff) |
Improve dictionaries not enabled badges (#1349)
* Improve badges on the settings page
* Add badges on the context page
Diffstat (limited to 'ext/bg/js/context-main.js')
-rw-r--r-- | ext/bg/js/context-main.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ext/bg/js/context-main.js b/ext/bg/js/context-main.js index 65853514..e9833687 100644 --- a/ext/bg/js/context-main.js +++ b/ext/bg/js/context-main.js @@ -100,6 +100,7 @@ class DisplayController { toggle.checked = extensionEnabled; toggle.addEventListener('change', onToggleChanged, false); } + this._updateDictionariesEnabledWarnings(options); } async _setupHotkeys() { @@ -150,6 +151,26 @@ class DisplayController { }] ); } + + async _updateDictionariesEnabledWarnings(options) { + const noDictionariesEnabledWarnings = document.querySelectorAll('.no-dictionaries-enabled-warning'); + const dictionaries = await api.getDictionaryInfo(); + + let enabledCount = 0; + for (const {title} of dictionaries) { + if ( + Object.prototype.hasOwnProperty.call(options.dictionaries, title) && + options.dictionaries[title].enabled + ) { + ++enabledCount; + } + } + + const hasEnabledDictionary = (enabledCount > 0); + for (const node of noDictionariesEnabledWarnings) { + node.hidden = hasEnabledDictionary; + } + } } (async () => { |