From 4b6703114c3fedaaf24cc7a376d885e22dfdc4f3 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 8 Feb 2021 17:52:46 -0500 Subject: Improve dictionaries not enabled badges (#1349) * Improve badges on the settings page * Add badges on the context page --- ext/bg/js/context-main.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'ext/bg/js') 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 () => { -- cgit v1.2.3