diff --git a/ext/js/pages/settings/dictionary-import-controller.js b/ext/js/pages/settings/dictionary-import-controller.js index 1c1b7720c4..12fb5a4bb8 100644 --- a/ext/js/pages/settings/dictionary-import-controller.js +++ b/ext/js/pages/settings/dictionary-import-controller.js @@ -176,8 +176,20 @@ export class DictionaryImportController { return; } + const installedDictionaries = await this._settingsController.getDictionaryInfo(); + /** @type {Set} */ + const installedDictionaryNames = new Set(); + /** @type {Set} */ + const installedDictionaryDownloadUrls = new Set(); + for (const dictionary of installedDictionaries) { + installedDictionaryNames.add(dictionary.title); + if (dictionary.downloadUrl) { + installedDictionaryDownloadUrls.add(dictionary.downloadUrl); + } + } + for (const {property, element} of recommendedDictionaryCategories) { - this._renderRecommendedDictionaryGroup(recommendedDictionaries[language][property], element); + this._renderRecommendedDictionaryGroup(recommendedDictionaries[language][property], element, installedDictionaryNames, installedDictionaryDownloadUrls); } /** @type {NodeListOf} */ @@ -191,8 +203,10 @@ export class DictionaryImportController { * * @param {import('dictionary-recommended.js').Dictionary[]} recommendedDictionaries * @param {HTMLElement} dictionariesList + * @param {Set} installedDictionaryNames + * @param {Set} installedDictionaryDownloadUrls */ - _renderRecommendedDictionaryGroup(recommendedDictionaries, dictionariesList) { + _renderRecommendedDictionaryGroup(recommendedDictionaries, dictionariesList, installedDictionaryNames, installedDictionaryDownloadUrls) { const dictionariesListParent = dictionariesList.parentElement; dictionariesList.innerHTML = ''; for (const dictionary of recommendedDictionaries) { @@ -202,7 +216,9 @@ export class DictionaryImportController { } const template = this._settingsController.instantiateTemplate('recommended-dictionaries-list-item'); const label = querySelectorNotNull(template, '.settings-item-label'); + /** @type {HTMLButtonElement} */ const button = querySelectorNotNull(template, '.action-button[data-action=import-recommended-dictionary]'); + button.disabled = installedDictionaryNames.has(dictionary.name) || installedDictionaryDownloadUrls.has(dictionary.url); const urlAttribute = document.createAttribute('data-import-url'); urlAttribute.value = dictionary.url;