Skip to content

Commit

Permalink
remove duplicate readings in term object
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvNC committed Mar 16, 2022
1 parent fd09dac commit 3026823
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions jpdb-freq-list.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @namespace https://github.com/MarvNC
// @match https://jpdb.io/deck
// @match https://jpdb.io/*/vocabulary-list*
// @version 1.18
// @version 1.19
// @require https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.7.1/jszip.min.js
// @author Marv
Expand Down Expand Up @@ -175,19 +175,23 @@ const entriesPerPage = 50;
// convert termEntries into array to export
// https://github.com/FooSoft/yomichan/blob/master/ext/data/schemas/dictionary-term-meta-bank-v3-schema.json
const termEntryData = (kanji, reading, freqValue, isKana = false) => {
let unused = freqValue >= firstUnused;
const unused = freqValue >= firstUnused;
freqValue = Math.min(freqValue, firstUnused);
return [
kanji,
'freq',
{
const frequency = {
value: freqValue,
displayValue: freqValue + (isKana ? kanaSymbol : '') + (unused ? unusedSymbol : ''),
};
let thirdValue;
// third value is just the freq if it doesn't have the reading, otherwise object with reading and freq.
if (kanji == reading) {
thirdValue = frequency;
} else {
thirdValue = {
reading: reading,
frequency: {
value: freqValue,
displayValue: freqValue + (isKana ? kanaSymbol : '') + (unused ? unusedSymbol : ''),
},
},
];
frequency: frequency,
};
}
return [kanji, 'freq', thirdValue];
};

for (const entryID in termEntries) {
Expand All @@ -207,7 +211,7 @@ const entriesPerPage = 50;
}

freqList.sort((a, b) => {
return a[2].frequency.value - b[2].frequency.value;
return (a[2].value ?? a[2].frequency?.value) - (b[2].value ?? b[2].frequency?.value);
});

let exportFileName = fileName(deckName);
Expand Down

0 comments on commit 3026823

Please sign in to comment.