Skip to content

Commit

Permalink
kanji support
Browse files Browse the repository at this point in the history
  • Loading branch information
ArmoryFou committed Mar 4, 2024
1 parent 3ce4496 commit bb0c914
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@

let answer = "";

function isCorrect(answer, correctAnswer) {
function isCorrect(answer, correctAnswer, correctKanji) {
const correct = correctAnswer.trim()
const user = answer.trim().replace("nn", "n'")

if(correctKanji){
if(answer == correctKanji){
return true;
}
}

if (wanakana.isHiragana(correctAnswer)) {
return correct === wanakana.toHiragana(user);
} else {
Expand Down Expand Up @@ -204,6 +210,22 @@
correctAnswer = correct.textContent;
}

let correctAnswerKanji = "";

if (correctChilds.length > 0) {
for (const child of correctChilds) {
const textContent = child.textContent;
const kanjiMatches = textContent.match(/[\u4e00-\u9faf]/g);

if (kanjiMatches) {
correctAnswerKanji += kanjiMatches.join("");
}
}
} else {
correctAnswerKanji = correct.textContent;
}


const answerElement = document.createElement("p");
answerElement.style.textAlign = "center";
answerElement.style.fontSize = "2rem";
Expand All @@ -226,7 +248,7 @@
checkElement.style.fontSize = "2rem";
checkElement.id = "respuestausuario";

if (isCorrect(answer, correctAnswer)) {
if (isCorrect(answer, correctAnswer, correctAnswerKanji)) {
chrome.runtime.sendMessage({ action: "addPoints", points: 1 });

checkElement.style.color = "#0F0";
Expand Down

0 comments on commit bb0c914

Please sign in to comment.