|
|
@ -433,6 +433,7 @@ export class WaniKani { |
|
|
|
ja: string; |
|
|
|
en: string; |
|
|
|
}[]; |
|
|
|
meaning: string; |
|
|
|
} |
|
|
|
>(); |
|
|
|
vocabularies.map((v) => { |
|
|
@ -442,6 +443,10 @@ export class WaniKani { |
|
|
|
sentenceMap.set(v.data.characters, { |
|
|
|
...sent, |
|
|
|
sentences: v.data.context_sentences, |
|
|
|
meaning: v.data.meanings |
|
|
|
.sort((m1, m2) => Number(m2.primary) - Number(m1.primary)) |
|
|
|
.map((m) => m.meaning) |
|
|
|
.join('; '), |
|
|
|
}); |
|
|
|
}); |
|
|
|
if (!sentenceMap.size) return; |
|
|
@ -476,23 +481,38 @@ export class WaniKani { |
|
|
|
[fields.sentenceEn]: sent.en, |
|
|
|
}; |
|
|
|
|
|
|
|
if ( |
|
|
|
fields.sentenceCloze && |
|
|
|
!n.fields[fields.sentenceCloze]?.value |
|
|
|
) { |
|
|
|
const clozeChar = '__'; |
|
|
|
let newSent = sent.sentences |
|
|
|
.map(({ ja, en }) => `${ja}<br/>${en}`) |
|
|
|
.join('<br/>') |
|
|
|
.replace(cleanJa, clozeChar); |
|
|
|
|
|
|
|
cleanJa.split(/[\p{sc=Hiragana}]+/gu).map((c) => { |
|
|
|
if (c) { |
|
|
|
newSent = newSent.replace(c, clozeChar); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
fieldUpdate[fields.sentenceCloze] = newSent; |
|
|
|
if (fields.sentenceCloze) { |
|
|
|
let clozeSent = n.fields[fields.sentenceCloze]?.value || ''; |
|
|
|
|
|
|
|
if (!clozeSent && sent.sentences.length) { |
|
|
|
const clozeChar = '__'; |
|
|
|
let newSent = sent.sentences |
|
|
|
.map(({ ja, en }) => `${ja}<br/>${en}`) |
|
|
|
.join('<br/>') |
|
|
|
.replace(cleanJa, clozeChar); |
|
|
|
|
|
|
|
cleanJa.split(/[\p{sc=Hiragana}]+/gu).map((c) => { |
|
|
|
if (c) { |
|
|
|
newSent = newSent.replace(c, clozeChar); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
fieldUpdate[fields.sentenceCloze] = newSent; |
|
|
|
clozeSent = newSent; |
|
|
|
} |
|
|
|
|
|
|
|
const notJa = '[^\\p{sc=Han}\\p{sc=Katakana}\\p{sc=Hiragana}]+'; |
|
|
|
|
|
|
|
if ( |
|
|
|
clozeSent && |
|
|
|
!new RegExp( |
|
|
|
`(^${notJa}<br/?>|<br/?><br/?>${notJa}$)`, |
|
|
|
'u', |
|
|
|
).test(clozeSent) |
|
|
|
) { |
|
|
|
fieldUpdate[fields.sentenceCloze] = |
|
|
|
sent.meaning + '<br><br>' + clozeSent; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
notesToUpdate.push({ |
|
|
|