Skip to content

Commit 039311f

Browse files
committed
Merge branch 'master' into double-pitch
2 parents 5fc05d0 + 2fc09f9 commit 039311f

12 files changed

Lines changed: 646 additions & 28 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Get Yomitan for Edge](https://img.shields.io/badge/dynamic/json?logo=puzzle&label=get%20yomitan%20for%20edge&style=for-the-badge&query=%24.version&url=https%3A%2F%2Fmicrosoftedge.microsoft.com%2Faddons%2Fgetproductdetailsbycrxid%2Fidelnfbbmikgfiejhgmddlbkfgiifnnn)](https://microsoftedge.microsoft.com/addons/detail/yomitan/idelnfbbmikgfiejhgmddlbkfgiifnnn)
66
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/yomidevs/yomitan/badge?style=for-the-badge)](https://securityscorecards.dev/viewer/?uri=github.com/yomidevs/yomitan)
77

8-
[![Discord](https://dcbadge.vercel.app/api/server/YkQrXW6TXF?style=for-the-badge)](https://discord.gg/YkQrXW6TXF)
8+
[![Discord](https://dcbadge.limes.pink/api/server/YkQrXW6TXF?style=for-the-badge)](https://discord.gg/YkQrXW6TXF)
99

1010
# Visit [yomitan.wiki](https://yomitan.wiki) to learn more!
1111

ext/data/recommended-settings.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,24 +286,29 @@
286286
"value": [
287287
[
288288
{
289-
"pattern": "l'",
289+
"pattern": "l('|’)",
290290
"ignoreCase": true,
291291
"replacement": ""
292292
},
293293
{
294-
"pattern": "j'",
294+
"pattern": "j('|’)",
295295
"ignoreCase": true,
296296
"replacement": ""
297297
},
298298
{
299-
"pattern": "d'",
299+
"pattern": "d('|’)",
300+
"ignoreCase": true,
301+
"replacement": ""
302+
},
303+
{
304+
"pattern": "s('|’)",
300305
"ignoreCase": true,
301306
"replacement": ""
302307
}
303308
]
304309
]
305310
},
306-
"description": "Separating the l', j', d' from the word."
311+
"description": "Separating the l', j', d', s' from the word."
307312
},
308313
{
309314
"modification": {
Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,47 @@
11
{{<<<<<<<}}
2-
{{#*inline "pitch-accent-item"}}
3-
{{~pronunciation format=format reading=reading downstepPosition=position nasalPositions=nasalPositions devoicePositions=devoicePositions~}}
2+
{{#*inline "frequencies"}}
3+
{{~#if (op ">" definition.frequencies.length 0)~}}
4+
<ul style="text-align: left;">
5+
{{~#each definition.frequencies~}}
6+
<li>
7+
{{~#if (op "!==" ../definition.type "kanji")~}}
8+
{{~#if (op "||" (op ">" ../uniqueExpressions.length 1) (op ">" ../uniqueReadings.length 1))~}}(
9+
{{~furigana expression reading~}}
10+
) {{/if~}}
11+
{{~/if~}}
12+
{{~dictionaryAlias}}: {{frequency~}}
13+
</li>
14+
{{~/each~}}
15+
</ul>
16+
{{~/if~}}
417
{{/inline}}
518
{{=======}}
6-
{{#*inline "pitch-accent-item"}}
7-
{{~pronunciation format=format reading=reading pitchPositions=positions nasalPositions=nasalPositions devoicePositions=devoicePositions~}}
19+
{{#*inline "frequencies"}}
20+
{{~#if (op ">" definition.frequencies.length 0)~}}
21+
<ul style="text-align: left;">
22+
{{~#each definition.frequencies~}}
23+
{{~#unless (op "&&" ../selectedDictionary (op "!=" ../selectedDictionary dictionary))~}}
24+
<li>
25+
{{~#if (op "!==" ../definition.type "kanji")~}}
26+
{{~#if (op "||" (op ">" ../uniqueExpressions.length 1) (op ">" ../uniqueReadings.length 1))~}}(
27+
{{~furigana expression reading~}}
28+
) {{/if~}}
29+
{{~/if~}}
30+
{{~dictionaryAlias}}: {{frequency~}}
31+
</li>
32+
{{~/unless~}}
33+
{{~/each~}}
34+
</ul>
35+
{{~/if~}}
836
{{/inline}}
937
{{>>>>>>>}}
38+
39+
{{#*inline "single-frequency-number"}}
40+
{{~#if (op ">" definition.frequencyNumbers.length 0)~}}
41+
{{~#each definition.frequencyNumbers~}}
42+
{{~#unless (op "&&" ../selectedDictionary (op "!=" ../selectedDictionary dictionary))~}}
43+
{{frequency~}}
44+
{{~/unless~}}
45+
{{~/each~}}
46+
{{/if}}
47+
{{/inline}}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{<<<<<<<}}
2+
{{#*inline "pitch-accent-item"}}
3+
{{~pronunciation format=format reading=reading downstepPosition=position nasalPositions=nasalPositions devoicePositions=devoicePositions~}}
4+
{{/inline}}
5+
{{=======}}
6+
{{#*inline "pitch-accent-item"}}
7+
{{~pronunciation format=format reading=reading pitchPositions=positions nasalPositions=nasalPositions devoicePositions=devoicePositions~}}
8+
{{/inline}}
9+
{{>>>>>>>}}

ext/data/templates/default-anki-field-templates.handlebars

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,19 +358,31 @@
358358
{{~#if (op ">" definition.frequencies.length 0)~}}
359359
<ul style="text-align: left;">
360360
{{~#each definition.frequencies~}}
361-
<li>
362-
{{~#if (op "!==" ../definition.type "kanji")~}}
363-
{{~#if (op "||" (op ">" ../uniqueExpressions.length 1) (op ">" ../uniqueReadings.length 1))~}}(
364-
{{~furigana expression reading~}}
365-
) {{/if~}}
366-
{{~/if~}}
367-
{{~dictionaryAlias}}: {{frequency~}}
368-
</li>
361+
{{~#unless (op "&&" ../selectedDictionary (op "!=" ../selectedDictionary dictionary))~}}
362+
<li>
363+
{{~#if (op "!==" ../definition.type "kanji")~}}
364+
{{~#if (op "||" (op ">" ../uniqueExpressions.length 1) (op ">" ../uniqueReadings.length 1))~}}(
365+
{{~furigana expression reading~}}
366+
) {{/if~}}
367+
{{~/if~}}
368+
{{~dictionaryAlias}}: {{frequency~}}
369+
</li>
370+
{{~/unless~}}
369371
{{~/each~}}
370372
</ul>
371373
{{~/if~}}
372374
{{/inline}}
373375

376+
{{#*inline "single-frequency-number"}}
377+
{{~#if (op ">" definition.frequencyNumbers.length 0)~}}
378+
{{~#each definition.frequencyNumbers~}}
379+
{{~#unless (op "&&" ../selectedDictionary (op "!=" ../selectedDictionary dictionary))~}}
380+
{{frequency~}}
381+
{{~/unless~}}
382+
{{~/each~}}
383+
{{/if}}
384+
{{/inline}}
385+
374386
{{#*inline "frequency-harmonic-rank"}}
375387
{{~#if (op "===" definition.frequencyHarmonic -1) ~}}
376388
9999999

ext/js/data/anki-note-data-creator.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function getPublicContext(context) {
171171

172172
/**
173173
* @param {import('dictionary').TermDictionaryEntry|import('dictionary').KanjiDictionaryEntry} dictionaryEntry
174-
* @returns {number[]}
174+
* @returns {import('anki-templates').FrequencyNumber[]}
175175
*/
176176
function getFrequencyNumbers(dictionaryEntry) {
177177
let previousDictionary;
@@ -187,13 +187,13 @@ function getFrequencyNumbers(dictionaryEntry) {
187187
if (frequencyMatch !== null) {
188188
const frequencyParsed = Number.parseInt(frequencyMatch[0], 10);
189189
if (frequencyParsed > 0) {
190-
frequencies.push(frequencyParsed);
190+
frequencies.push({dictionary: dictionary, frequency: frequencyParsed});
191191
continue;
192192
}
193193
}
194194
}
195195
if (frequency > 0) {
196-
frequencies.push(frequency);
196+
frequencies.push({dictionary: dictionary, frequency: frequency});
197197
}
198198
}
199199
return frequencies;
@@ -212,7 +212,7 @@ function getFrequencyHarmonic(dictionaryEntry) {
212212

213213
let total = 0;
214214
for (const frequency of frequencies) {
215-
total += 1 / frequency;
215+
total += 1 / frequency.frequency;
216216
}
217217
return Math.floor(frequencies.length / total);
218218
}
@@ -230,7 +230,7 @@ function getFrequencyAverage(dictionaryEntry) {
230230

231231
let total = 0;
232232
for (const frequency of frequencies) {
233-
total += frequency;
233+
total += frequency.frequency;
234234
}
235235
return Math.floor(total / frequencies.length);
236236
}
@@ -441,6 +441,7 @@ function getTermDefinition(dictionaryEntry, context, resultOutputMode, dictionar
441441
const termTags = createCachedValue(getTermTags.bind(null, dictionaryEntry, type));
442442
const expressions = createCachedValue(getTermExpressions.bind(null, dictionaryEntry));
443443
const frequencies = createCachedValue(getTermFrequencies.bind(null, dictionaryEntry));
444+
const frequencyNumbers = createCachedValue(getFrequencyNumbers.bind(null, dictionaryEntry));
444445
const frequencyHarmonic = createCachedValue(getFrequencyHarmonic.bind(null, dictionaryEntry));
445446
const frequencyAverage = createCachedValue(getFrequencyAverage.bind(null, dictionaryEntry));
446447
const pitches = createCachedValue(getTermPitches.bind(null, dictionaryEntry));
@@ -483,6 +484,7 @@ function getTermDefinition(dictionaryEntry, context, resultOutputMode, dictionar
483484
get termTags() { return getCachedValue(termTags); },
484485
get definitions() { return getCachedValue(commonInfo).definitions; },
485486
get frequencies() { return getCachedValue(frequencies); },
487+
get frequencyNumbers() { return getCachedValue(frequencyNumbers); },
486488
get frequencyHarmonic() { return getCachedValue(frequencyHarmonic); },
487489
get frequencyAverage() { return getCachedValue(frequencyAverage); },
488490
get pitches() { return getCachedValue(pitches); },

ext/js/data/anki-template-util.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ export function getDynamicTemplates(options, dictionaryInfo) {
122122
const currentDictionaryInfo = dictionaryInfo.find(({title}) => title === dictionary.name);
123123
if (!dictionary.enabled) { continue; }
124124
const totalTerms = currentDictionaryInfo?.counts?.terms?.total;
125-
if (!totalTerms || totalTerms === 0) { continue; }
126-
dynamicTemplates += `
125+
if (totalTerms && totalTerms > 0) {
126+
dynamicTemplates += `
127127
{{#*inline "single-glossary-${getKebabCase(dictionary.name)}"}}
128128
{{~> glossary selectedDictionary='${escapeDictName(dictionary.name)}'}}
129129
{{/inline}}
@@ -144,6 +144,18 @@ export function getDynamicTemplates(options, dictionaryInfo) {
144144
{{~> glossary-plain-no-dictionary selectedDictionary='${escapeDictName(dictionary.name)}' noDictionaryTag=true}}
145145
{{/inline}}
146146
`;
147+
}
148+
const totalMeta = currentDictionaryInfo?.counts?.termMeta;
149+
if (totalMeta && totalMeta.freq && totalMeta.freq > 0) {
150+
dynamicTemplates += `
151+
{{#*inline "single-frequency-number-${getKebabCase(dictionary.name)}"}}
152+
{{~> single-frequency-number selectedDictionary='${escapeDictName(dictionary.name)}'}}
153+
{{/inline}}
154+
{{#*inline "single-frequency-${getKebabCase(dictionary.name)}"}}
155+
{{~> frequencies selectedDictionary='${escapeDictName(dictionary.name)}'}}
156+
{{/inline}}
157+
`;
158+
}
147159
}
148160
return dynamicTemplates;
149161
}
@@ -159,8 +171,13 @@ export function getDynamicFieldMarkers(dictionaries, dictionaryInfo) {
159171
const currentDictionaryInfo = dictionaryInfo.find(({title}) => title === dictionary.name);
160172
if (!dictionary.enabled) { continue; }
161173
const totalTerms = currentDictionaryInfo?.counts?.terms?.total;
162-
if (!totalTerms || totalTerms === 0) { continue; }
163-
markers.push(`single-glossary-${getKebabCase(dictionary.name)}`);
174+
if (totalTerms && totalTerms > 0) {
175+
markers.push(`single-glossary-${getKebabCase(dictionary.name)}`);
176+
}
177+
const totalMeta = currentDictionaryInfo?.counts?.termMeta;
178+
if (totalMeta && totalMeta.freq && totalMeta.freq > 0) {
179+
markers.push(`single-frequency-number-${getKebabCase(dictionary.name)}`);
180+
}
164181
}
165182
return markers;
166183
}

ext/js/data/options-util.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ export class OptionsUtil {
579579
this._updateVersion65,
580580
this._updateVersion66,
581581
this._updateVersion67,
582+
this._updateVersion68,
582583
];
583584
/* eslint-enable @typescript-eslint/unbound-method */
584585
if (typeof targetVersion === 'number' && targetVersion < result.length) {
@@ -1747,13 +1748,21 @@ export class OptionsUtil {
17471748
}
17481749

17491750
/**
1750-
* - Changed pitch-accent-item param name
1751+
* - Added dynamic handlebars for single frequency dictionaries.
17511752
* @type {import('options-util').UpdateFunction}
17521753
*/
17531754
async _updateVersion67(options) {
17541755
await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v67.handlebars');
17551756
}
17561757

1758+
/**
1759+
* - Changed pitch-accent-item param name
1760+
* @type {import('options-util').UpdateFunction}
1761+
*/
1762+
async _updateVersion68(options) {
1763+
await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v68.handlebars');
1764+
}
1765+
17571766
/**
17581767
* @param {string} url
17591768
* @returns {Promise<chrome.tabs.Tab>}

ext/templates-modals.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,14 @@ <h1 class="modal-title">Pronunciation Dictionaries</h1>
11711171
Defaults to 0 occurrences when frequency data is not found, the lowest possible occurrence-based term or kanji usage.
11721172
</td>
11731173
</tr>
1174+
<tr>
1175+
<td><code class="anki-field-marker">{single-frequency-DICT-NAME}</code></td>
1176+
<td>All frequencies from the selected dictionary put in a list.</td>
1177+
</tr>
1178+
<tr>
1179+
<td><code class="anki-field-marker">{single-frequency-number-DICT-NAME}</code></td>
1180+
<td>A single frequency number from the selected dictionary with no formatting data.</td>
1181+
</tr>
11741182
<tr>
11751183
<td><code class="anki-field-marker">{screenshot}</code></td>
11761184
<td>Screenshot of the web page taken at the time the term or kanji was added.</td>

0 commit comments

Comments
 (0)