From 26b07153acc5348a5b471d4a461ff9775e6e6457 Mon Sep 17 00:00:00 2001 From: Ren Tatsumoto Date: Wed, 7 Feb 2024 23:31:26 +0300 Subject: [PATCH] refactor odaka function --- .../Japanese sentences/Recognition/front.html | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/templates/Japanese sentences/Recognition/front.html b/templates/Japanese sentences/Recognition/front.html index 5823760..47a615d 100644 --- a/templates/Japanese sentences/Recognition/front.html +++ b/templates/Japanese sentences/Recognition/front.html @@ -31,7 +31,7 @@ Fri Jul 7 06:33:50 PM UTC 2023
-
{{VocabKanji}}
+
{{VocabKanji}}
{{VocabPitchNum}}
{{kana:VocabFurigana}}
@@ -82,30 +82,16 @@ Fri Jul 7 06:33:50 PM UTC 2023 function odaka(pitch_num) { // word is odaka if number of moras is equal to pitch accent position - const vocab_kana = document.getElementById("kanaword_hidden"); - if (vocab_kana === null) { - return false; - } - let moras = vocab_kana.innerHTML + const moras = document.getElementById("kanaword_hidden").innerText .replace(/[((<].*[>))]/, "") // remove (お), (する), <する>, <な>, etc .replace(/[ャュョゃゅょ]/g, "") // small っ is one mora; ゃゅょ are parts of single mora .trim(); - - let n_moras; // first determine if な is part of pronunciation or な-adjective (e.g. 女) - const vocab_kanji = document.getElementById("vocab_kanji").innerHTML.trim(); - if (/な$/.test(vocab_kanji)) { - // な-adjectives don't change pitch - n_moras = moras.replace(/な$/, "").length; - } else { - n_moras = moras.length; - } - - if (n_moras == pitch_num) { - return true; - } else { - return false; - } + const vocab_kanji = document.getElementById("vocab_kanji_hidden") + .innerText + .trim(); + const n_moras = (/な$/.test(vocab_kanji)) ? moras.replace(/な$/, "").length : moras.length; + return (n_moras == pitch_num); } /* Splits tags into separate divs */