diff --git a/ext/js/dictionary/dictionary-data-util.js b/ext/js/dictionary/dictionary-data-util.js index 1b337d53a..46fb8e924 100644 --- a/ext/js/dictionary/dictionary-data-util.js +++ b/ext/js/dictionary/dictionary-data-util.js @@ -94,7 +94,7 @@ export function groupTermFrequencies(dictionaryEntry, dictionaryInfo) { }); } const currentDictionaryInfo = dictionaryInfo.find(({title}) => title === dictionary); - const freqCount = currentDictionaryInfo?.counts.termMeta.freq ?? 0; + const freqCount = currentDictionaryInfo?.counts?.termMeta.freq ?? 0; results.push({dictionary, frequencies, dictionaryAlias, freqCount}); } return results; @@ -138,7 +138,7 @@ export function groupKanjiFrequencies(sourceFrequencies, dictionaryInfo) { }); } const currentDictionaryInfo = dictionaryInfo.find(({title}) => title === dictionary); - const freqCount = currentDictionaryInfo?.counts.kanjiMeta.freq ?? 0; + const freqCount = currentDictionaryInfo?.counts?.kanjiMeta.freq ?? 0; results.push({dictionary, frequencies, dictionaryAlias, freqCount}); } return results; diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js index b163e01ab..e19dbb61b 100644 --- a/ext/js/display/display-generator.js +++ b/ext/js/display/display-generator.js @@ -159,8 +159,8 @@ export class DisplayGenerator { dictionaryContentArray.push('URL: ' + currentDictionaryInfo.url); } - const totalTerms = currentDictionaryInfo.counts.terms.total; - if (totalTerms > 0) { + const totalTerms = currentDictionaryInfo?.counts?.terms?.total; + if (!!totalTerms && totalTerms > 0) { dictionaryContentArray.push('Term Count: ' + totalTerms.toString()); } @@ -218,8 +218,8 @@ export class DisplayGenerator { dictionaryContentArray.push('URL: ' + currentDictionaryInfo.url); } - const totalKanji = currentDictionaryInfo.counts.kanji.total; - if (totalKanji > 0) { + const totalKanji = currentDictionaryInfo?.counts?.kanji?.total; + if (!!totalKanji && totalKanji > 0) { dictionaryContentArray.push('Kanji Count: ' + totalKanji.toString()); } diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js index 5f4a44035..e2fcf1e32 100644 --- a/ext/js/pages/settings/dictionary-controller.js +++ b/ext/js/pages/settings/dictionary-controller.js @@ -274,10 +274,10 @@ class DictionaryEntry { outdateElement.hidden = (version >= 3); countsElement.textContent = this._counts !== null ? JSON.stringify(this._counts, null, 4) : ''; wildcardSupportedElement.checked = prefixWildcardsSupported; - partsOfSpeechFilterSetting.hidden = !counts.terms.total; + partsOfSpeechFilterSetting.hidden = !counts?.terms.total; partsOfSpeechFilterToggle.dataset.setting = `dictionaries[${this._index}].partsOfSpeechFilter`; - useDeinflectionsSetting.hidden = !counts.terms.total; + useDeinflectionsSetting.hidden = !counts?.terms.total; useDeinflectionsToggle.dataset.setting = `dictionaries[${this._index}].useDeinflections`; this._setupDetails(detailsTableElement); diff --git a/types/ext/dictionary-importer.d.ts b/types/ext/dictionary-importer.d.ts index 9dd50a68a..97472e6cf 100644 --- a/types/ext/dictionary-importer.d.ts +++ b/types/ext/dictionary-importer.d.ts @@ -49,7 +49,7 @@ export type Summary = { version: number; importDate: number; prefixWildcardsSupported: boolean; - counts: SummaryCounts; + counts?: SummaryCounts; styles: string; isUpdatable?: boolean; indexUrl?: string;