From 9899727d7d53caed4c5b5e68176f7ed7f90a9438 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 26 Sep 2021 11:08:16 -0400 Subject: Frequency dictionary sort (#1938) * Add sortDictionary/sortDictionaryOrder options * Update options * Add API.getTermFrequencies * Add settings * Implement frequency dictionary sorting * Update test * Update test data * Fix handling of undefined rank-based frequencies --- ext/js/background/backend.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'ext/js/background/backend.js') diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index b9e1f51b..e76f4cfe 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -125,7 +125,8 @@ class Backend { ['triggerDatabaseUpdated', {async: false, contentScript: true, handler: this._onApiTriggerDatabaseUpdated.bind(this)}], ['testMecab', {async: true, contentScript: true, handler: this._onApiTestMecab.bind(this)}], ['textHasJapaneseCharacters', {async: false, contentScript: true, handler: this._onApiTextHasJapaneseCharacters.bind(this)}], - ['documentStart', {async: false, contentScript: true, handler: this._onApiDocumentStart.bind(this)}] + ['documentStart', {async: false, contentScript: true, handler: this._onApiDocumentStart.bind(this)}], + ['getTermFrequencies', {async: true, contentScript: true, handler: this._onApiGetTermFrequencies.bind(this)}] ]); this._messageHandlersWithProgress = new Map([ ]); @@ -748,6 +749,10 @@ class Backend { this._updateTabAccessibility(url, tab, frameId); } + async _onApiGetTermFrequencies({termReadingList, dictionaries}) { + return await this._translator.getTermFrequencies(termReadingList, dictionaries); + } + // Command handlers async _onCommandOpenSearchPage(params) { @@ -1953,7 +1958,7 @@ class Backend { const {wildcard} = details; const enabledDictionaryMap = this._getTranslatorEnabledDictionaryMap(options); const { - general: {mainDictionary}, + general: {mainDictionary, sortFrequencyDictionary, sortFrequencyDictionaryOrder}, scanning: {alphanumeric}, translation: { convertHalfWidthCharacters, @@ -1979,6 +1984,8 @@ class Backend { return { wildcard, mainDictionary, + sortFrequencyDictionary, + sortFrequencyDictionaryOrder, removeNonJapaneseCharacters: !alphanumeric, convertHalfWidthCharacters, convertNumericCharacters, -- cgit v1.2.3