diff --git a/ext/js/dictionary/dictionary-data-util.js b/ext/js/dictionary/dictionary-data-util.js index 8ff1b625a..1b337d53a 100644 --- a/ext/js/dictionary/dictionary-data-util.js +++ b/ext/js/dictionary/dictionary-data-util.js @@ -51,9 +51,10 @@ export function groupTermTags(dictionaryEntry) { /** * @param {import('dictionary').TermDictionaryEntry} dictionaryEntry + * @param {import('dictionary-importer').Summary[]} dictionaryInfo * @returns {import('dictionary-data-util').DictionaryFrequency[]} */ -export function groupTermFrequencies(dictionaryEntry) { +export function groupTermFrequencies(dictionaryEntry, dictionaryInfo) { const {headwords, frequencies: sourceFrequencies} = dictionaryEntry; /** @type {import('dictionary-data-util').TermFrequenciesMap1} */ @@ -92,16 +93,19 @@ export function groupTermFrequencies(dictionaryEntry) { values: [...values.values()], }); } - results.push({dictionary, frequencies, dictionaryAlias}); + const currentDictionaryInfo = dictionaryInfo.find(({title}) => title === dictionary); + const freqCount = currentDictionaryInfo?.counts.termMeta.freq ?? 0; + results.push({dictionary, frequencies, dictionaryAlias, freqCount}); } return results; } /** * @param {import('dictionary').KanjiFrequency[]} sourceFrequencies + * @param {import('dictionary-importer').Summary[]} dictionaryInfo * @returns {import('dictionary-data-util').DictionaryFrequency[]} */ -export function groupKanjiFrequencies(sourceFrequencies) { +export function groupKanjiFrequencies(sourceFrequencies, dictionaryInfo) { /** @type {import('dictionary-data-util').KanjiFrequenciesMap1} */ const map1 = new Map(); /** @type {Map} */ @@ -133,7 +137,9 @@ export function groupKanjiFrequencies(sourceFrequencies) { values: [...values.values()], }); } - results.push({dictionary, frequencies, dictionaryAlias}); + const currentDictionaryInfo = dictionaryInfo.find(({title}) => title === dictionary); + 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 6f4d7e6cb..4c544fd02 100644 --- a/ext/js/display/display-generator.js +++ b/ext/js/display/display-generator.js @@ -66,9 +66,10 @@ export class DisplayGenerator { /** * @param {import('dictionary').TermDictionaryEntry} dictionaryEntry + * @param {import('dictionary-importer').Summary[]} dictionaryInfo * @returns {HTMLElement} */ - createTermEntry(dictionaryEntry) { + createTermEntry(dictionaryEntry, dictionaryInfo) { const node = this._instantiate('term-entry'); const headwordsContainer = this._querySelector(node, '.headword-list'); @@ -81,7 +82,7 @@ export class DisplayGenerator { const {headwords, type, inflectionRuleChainCandidates, definitions, frequencies, pronunciations} = dictionaryEntry; const groupedPronunciations = getGroupedPronunciations(dictionaryEntry); const pronunciationCount = groupedPronunciations.reduce((i, v) => i + v.pronunciations.length, 0); - const groupedFrequencies = groupTermFrequencies(dictionaryEntry); + const groupedFrequencies = groupTermFrequencies(dictionaryEntry, dictionaryInfo); const termTags = groupTermTags(dictionaryEntry); /** @type {Set} */ @@ -143,6 +144,28 @@ export class DisplayGenerator { dictionaryTag.dictionaries.push(dictionary); dictionaryTag.name = dictionaryAlias; dictionaryTag.content = [dictionary]; + + const currentDictionaryInfo = dictionaryInfo.find(({title}) => title === dictionary); + if (currentDictionaryInfo) { + const dictionaryContentArray = []; + dictionaryContentArray.push(currentDictionaryInfo.title); + if (currentDictionaryInfo.author) { + dictionaryContentArray.push('Author: ' + currentDictionaryInfo.author); + } + if (currentDictionaryInfo.description) { + dictionaryContentArray.push('Description: ' + currentDictionaryInfo.description); + } + if (currentDictionaryInfo.url) { + dictionaryContentArray.push('URL: ' + currentDictionaryInfo.url); + } + + const totalTerms = currentDictionaryInfo.counts.terms.total; + if (totalTerms > 0) { + dictionaryContentArray.push('Term Count: ' + totalTerms.toString()); + } + + dictionaryTag.content = dictionaryContentArray; + } } const node2 = this._createTermDefinition(definition, dictionaryTag, headwords, uniqueTerms, uniqueReadings); @@ -156,9 +179,10 @@ export class DisplayGenerator { /** * @param {import('dictionary').KanjiDictionaryEntry} dictionaryEntry + * @param {import('dictionary-importer').Summary[]} dictionaryInfo * @returns {HTMLElement} */ - createKanjiEntry(dictionaryEntry) { + createKanjiEntry(dictionaryEntry, dictionaryInfo) { const node = this._instantiate('kanji-entry'); node.dataset.dictionary = dictionaryEntry.dictionary; @@ -175,11 +199,32 @@ export class DisplayGenerator { this._setTextContent(glyphContainer, dictionaryEntry.character, this._language); if (this._language === 'ja') { glyphContainer.style.fontFamily = 'kanji-stroke-orders, sans-serif'; } - const groupedFrequencies = groupKanjiFrequencies(dictionaryEntry.frequencies); + const groupedFrequencies = groupKanjiFrequencies(dictionaryEntry.frequencies, dictionaryInfo); const dictionaryTag = this._createDictionaryTag(''); dictionaryTag.name = dictionaryEntry.dictionaryAlias; dictionaryTag.content = [dictionaryEntry.dictionary]; + const currentDictionaryInfo = dictionaryInfo.find(({title}) => title === dictionaryEntry.dictionary); + if (currentDictionaryInfo) { + const dictionaryContentArray = []; + dictionaryContentArray.push(currentDictionaryInfo.title); + if (currentDictionaryInfo.author) { + dictionaryContentArray.push('Author: ' + currentDictionaryInfo.author); + } + if (currentDictionaryInfo.description) { + dictionaryContentArray.push('Description: ' + currentDictionaryInfo.description); + } + if (currentDictionaryInfo.url) { + dictionaryContentArray.push('URL: ' + currentDictionaryInfo.url); + } + + const totalKanji = currentDictionaryInfo.counts.kanji.total; + if (totalKanji > 0) { + dictionaryContentArray.push('Kanji Count: ' + totalKanji.toString()); + } + + dictionaryTag.content = dictionaryContentArray; + } this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, true); this._appendMultiple(tagContainer, this._createTag.bind(this), [...dictionaryEntry.tags, dictionaryTag]); @@ -828,7 +873,7 @@ export class DisplayGenerator { body.dataset.count = `${ii}`; node.dataset.count = `${ii}`; node.dataset.details = dictionary; - tag.dataset.details = dictionary; + tag.dataset.details = dictionary + '\nFrequency Count: ' + details.freqCount?.toString(); return node; } diff --git a/ext/js/display/display.js b/ext/js/display/display.js index a85d84948..8a01a579d 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -196,6 +196,8 @@ export class Display extends EventDispatcher { this._themeController = new ThemeController(document.documentElement); /** @type {import('language').LanguageSummary[]} */ this._languageSummaries = []; + /** @type {import('dictionary-importer').Summary[]} */ + this._dictionaryInfo = []; /* eslint-disable @stylistic/no-multi-spaces */ this._hotkeyHandler.registerActions([ @@ -322,6 +324,8 @@ export class Display extends EventDispatcher { this._languageSummaries = await this._application.api.getLanguageSummaries(); + this._dictionaryInfo = await this._application.api.getDictionaryInfo(); + // Prepare await this._hotkeyHelpController.prepare(this._application.api); await this._displayGenerator.prepare(); @@ -1415,8 +1419,8 @@ export class Display extends EventDispatcher { const dictionaryEntry = dictionaryEntries[i]; const entry = ( dictionaryEntry.type === 'term' ? - this._displayGenerator.createTermEntry(dictionaryEntry) : - this._displayGenerator.createKanjiEntry(dictionaryEntry) + this._displayGenerator.createTermEntry(dictionaryEntry, this._dictionaryInfo) : + this._displayGenerator.createKanjiEntry(dictionaryEntry, this._dictionaryInfo) ); entry.dataset.index = `${i}`; this._dictionaryEntryNodes.push(entry); diff --git a/types/ext/dictionary-data-util.d.ts b/types/ext/dictionary-data-util.d.ts index 0636db9b8..b6d89f465 100644 --- a/types/ext/dictionary-data-util.d.ts +++ b/types/ext/dictionary-data-util.d.ts @@ -49,6 +49,7 @@ export type DictionaryFrequency = { dictionary: string; dictionaryAlias: string; frequencies: T[]; + freqCount: number; }; export type TermFrequency = {