Skip to content

Instantly share code, notes, and snippets.

@ammarfaizi2
Created February 5, 2024 18:53
Show Gist options
  • Save ammarfaizi2/ebcb7709a9fdda8a7ea18e839124a51a to your computer and use it in GitHub Desktop.
Save ammarfaizi2/ebcb7709a9fdda8a7ea18e839124a51a to your computer and use it in GitHub Desktop.
let rdx = document.getElementById('rdx');
let c = rdx.children;
let arr = [];
for (i of c) {
let x = i.children;
if (x.length < 4)
continue;
if (!x[0].innerText || !x[1].innerText || !x[2].innerText)
continue;
let code = x[0].innerText;
let name = x[1].innerText;
let kanji = x[2].innerText;
let tmp = code.split('\n');
if (tmp.length == 3)
tmp = [tmp[1], tmp[2]];
code = tmp.join(' ');
if (code.substr(0, 3) != 'KK ') {
code = x[1].innerText;
name = x[2].innerText;
kanji = x[3].innerText;
tmp = code.split('\n');
if (tmp.length == 3)
tmp = [tmp[1], tmp[2]];
code = tmp.join(' ');
if (code.substr(0, 3) != 'KK ')
continue;
}
let obj = {
n: code.replace(' ', ''),
romaji: name.toLowerCase(),
kanji: kanji
};
arr.push(obj);
console.log(obj);
}
// Sort by code
arr.sort((a, b) => {
let x = a.code;
let y = b.code;
return x < y ? -1 : x > y ? 1 : 0;
});
// Clear duplicates
let tmp = {};
arr = arr.filter((obj) => {
if (tmp[obj.code])
return false;
tmp[obj.code] = true;
return true;
});
console.log(JSON.stringify(arr, null, 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment