0a4659f7e6
Converts Japanese vocab (Kanji/Hiragana/English) to Anki CSV format. Served on port 4002 with a dark-themed two-panel UI. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
54 lines
1.1 KiB
JavaScript
54 lines
1.1 KiB
JavaScript
/*
|
|
takes in a string in the form of:
|
|
Kanji text
|
|
Hiragana
|
|
EN translation; alternative; alternative
|
|
|
|
and converts it to:
|
|
|
|
Kanji, Hiragana, EN translation; alternative; alternative
|
|
EN translation; alternative; alternative, Kanji, Hiragana
|
|
*/
|
|
|
|
var toExport = "";
|
|
|
|
function readyForImport(l1, l2, l3)
|
|
{
|
|
var front = l1 + ",\"" + l2 + "\n" + l3 + "\"";
|
|
var back = l3 + ",\"" + l1 + "\n" + l2 +"\"";
|
|
|
|
toExport += "\n" + front + "\n" + back;
|
|
}
|
|
|
|
function splitIntoComponents(toSplit)
|
|
{
|
|
var lines = toSplit.split("\n");
|
|
|
|
for (var i = 0; i<lines.length; i+=4)
|
|
{
|
|
readyForImport(lines[i], lines[i+1], lines[i+2]);
|
|
}
|
|
}
|
|
|
|
function createFile(input)
|
|
{
|
|
createString(input);
|
|
|
|
var link = document.createElement('a');
|
|
link.download = 'data.json';
|
|
var blob = new Blob([toExport], {type: 'text/plain', endings:'native'});
|
|
link.href = window.URL.createObjectURL(blob);
|
|
link.click();
|
|
}
|
|
|
|
function createString(input)
|
|
{
|
|
toExport = "";
|
|
splitIntoComponents(input);
|
|
toExport = toExport.substring(1); //remove first \n
|
|
console.log(toExport);
|
|
|
|
return toExport
|
|
}
|
|
|