From cda116eb8225f66ee5810e8acb153a0c43578e95 Mon Sep 17 00:00:00 2001 From: Jason Ojisan Date: Mon, 15 Jul 2024 03:38:55 +0700 Subject: [PATCH] Add helper text when search with no dictionaries enabled * Helper text when no dictionary enabled * Don't need to search if there is no dictionary entries * update helper link MTgxNDliNmIzZTM5NzFiYmM4ZGRlNmIyOTE0YmM4YmEwOTQ2YjQwYwo= --- ext/js/display/display.js | 19 +++++++++++++++++-- ext/popup.html | 6 ++++++ ext/search.html | 6 ++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ext/js/display/display.js b/ext/js/display/display.js index 1cd6ef5d3d..e984d7ff56 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -1296,6 +1296,7 @@ export class Display extends EventDispatcher { async _setContentTermsOrKanji(type, urlSearchParams, token) { const lookup = (urlSearchParams.get('lookup') !== 'false'); const wildcardsEnabled = (urlSearchParams.get('wildcards') !== 'off'); + const hasEnabledDictionaries = this._options ? this._options.dictionaries.some(({enabled}) => enabled) : false; // Set query let query = urlSearchParams.get('query'); @@ -1331,7 +1332,7 @@ export class Display extends EventDispatcher { let {dictionaryEntries} = content; if (!Array.isArray(dictionaryEntries)) { - dictionaryEntries = lookup && query.length > 0 ? await this._findDictionaryEntries(type === 'kanji', query, wildcardsEnabled, optionsContext) : []; + dictionaryEntries = hasEnabledDictionaries && lookup && query.length > 0 ? await this._findDictionaryEntries(type === 'kanji', query, wildcardsEnabled, optionsContext) : []; if (this._setContentToken !== token) { return; } content.dictionaryEntries = dictionaryEntries; changeHistory = true; @@ -1367,7 +1368,8 @@ export class Display extends EventDispatcher { this._dictionaryEntries = dictionaryEntries; this._updateNavigationAuto(); - this._setNoContentVisible(dictionaryEntries.length === 0 && lookup); + this._setNoContentVisible(hasEnabledDictionaries && dictionaryEntries.length === 0 && lookup); + this._setNoDictionariesVisible(!hasEnabledDictionaries); const container = this._container; container.textContent = ''; @@ -1424,6 +1426,7 @@ export class Display extends EventDispatcher { this._updateNavigation(false, false); this._setNoContentVisible(false); + this._setNoDictionariesVisible(false); this._setQuery('', '', 0); this._triggerContentUpdateStart(); @@ -1452,6 +1455,18 @@ export class Display extends EventDispatcher { } } + /** + * @param {boolean} visible + */ + _setNoDictionariesVisible(visible) { + /** @type {?HTMLElement} */ + const noDictionaries = document.querySelector('#no-dictionaries'); + + if (noDictionaries !== null) { + noDictionaries.hidden = !visible; + } + } + /** * @param {string} query * @param {string} fullQuery diff --git a/ext/popup.html b/ext/popup.html index b5ac401ef0..5f7c419f21 100644 --- a/ext/popup.html +++ b/ext/popup.html @@ -45,6 +45,12 @@ + +