japanese sentences: add jp1k support
This commit is contained in:
parent
658c100e63
commit
2a03a0e923
|
@ -7,28 +7,34 @@ Wed Feb 7 08:30:09 PM UTC 2024
|
||||||
<header>
|
<header>
|
||||||
{{#Focus}}
|
{{#Focus}}
|
||||||
<div class="tags">{{Focus}}</div>
|
<div class="tags">{{Focus}}</div>
|
||||||
{{/Focus}}
|
{{/Focus}} {{#Tags}}
|
||||||
{{#Tags}}
|
|
||||||
<div class="tags">{{Tags}}</div>
|
<div class="tags">{{Tags}}</div>
|
||||||
{{/Tags}}
|
{{/Tags}}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="sent-center">
|
<div class="sent-center" id="tsc" visible="true">
|
||||||
|
<!-- this tag is hidden on the front. -->
|
||||||
<div class="jpsentence" lang="ja">
|
<div class="jpsentence" lang="ja">
|
||||||
{{edit:furigana:SentKanji}}
|
{{edit:furigana:SentKanji}} {{^SentKanji}}
|
||||||
{{^SentKanji}}
|
|
||||||
<nokana>{{edit:kanji:SentFurigana}}</nokana>
|
<nokana>{{edit:kanji:SentFurigana}}</nokana>
|
||||||
{{/SentKanji}}
|
{{/SentKanji}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="sent-center" id="jp1k-tsc" visible="false">
|
||||||
|
<!-- JP1K mode is active only if note has been tagged as jp1k. -->
|
||||||
|
<div class="jpsentence" lang="ja">{{furigana:SentFurigana}}</div>
|
||||||
|
<button class="toggle_furigana_button" onclick="toggle_jp1k_furigana();">Toggle Readings</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
{{#Image}}
|
{{#Image}}
|
||||||
<details class="images-on-front images-details">
|
<details class="images-on-front images-details">
|
||||||
<summary>Image</summary>
|
<summary>Image</summary>
|
||||||
<div class="images">{{Image}}</div>
|
<div class="images">{{Image}}</div>
|
||||||
</details>
|
</details>
|
||||||
{{/Image}}
|
{{/Image}}
|
||||||
</div> <!-- /wrap -->
|
</div>
|
||||||
|
<!-- /wrap -->
|
||||||
|
|
||||||
<div style="display: none">
|
<div style="display: none">
|
||||||
<div id="vocab_kanji_hidden">{{VocabKanji}}</div>
|
<div id="vocab_kanji_hidden">{{VocabKanji}}</div>
|
||||||
|
@ -47,15 +53,12 @@ Wed Feb 7 08:30:09 PM UTC 2024
|
||||||
let pitchNumber = document.getElementById("pitchnum_hidden");
|
let pitchNumber = document.getElementById("pitchnum_hidden");
|
||||||
if (pitchNumber === null) {
|
if (pitchNumber === null) {
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
pitchNumber = pitchNumber.innerHTML.match(/\d/);
|
|
||||||
}
|
}
|
||||||
|
pitchNumber = pitchNumber.innerHTML.match(/\d/);
|
||||||
if (pitchNumber === null) {
|
if (pitchNumber === null) {
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
pitchNumber = Number(pitchNumber);
|
|
||||||
}
|
}
|
||||||
|
pitchNumber = Number(pitchNumber);
|
||||||
/* Then decide what color to use and change font color accordingly. */
|
/* Then decide what color to use and change font color accordingly. */
|
||||||
if (pitchNumber == 0) {
|
if (pitchNumber == 0) {
|
||||||
// use blue for 平板
|
// use blue for 平板
|
||||||
|
@ -64,7 +67,7 @@ Wed Feb 7 08:30:09 PM UTC 2024
|
||||||
// use red for 頭高
|
// use red for 頭高
|
||||||
paintTargetWord("red");
|
paintTargetWord("red");
|
||||||
} else if (pitchNumber > 1) {
|
} else if (pitchNumber > 1) {
|
||||||
if (odaka(pitchNumber)) {
|
if (is_odaka(pitchNumber)) {
|
||||||
// use green for 尾高
|
// use green for 尾高
|
||||||
paintTargetWord("green");
|
paintTargetWord("green");
|
||||||
} else {
|
} else {
|
||||||
|
@ -80,7 +83,7 @@ Wed Feb 7 08:30:09 PM UTC 2024
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function odaka(pitch_num) {
|
function is_odaka(pitch_num) {
|
||||||
// word is odaka if number of moras is equal to pitch accent position
|
// word is odaka if number of moras is equal to pitch accent position
|
||||||
const moras = document
|
const moras = document
|
||||||
.getElementById("kanaword_hidden")
|
.getElementById("kanaword_hidden")
|
||||||
|
@ -97,7 +100,9 @@ Wed Feb 7 08:30:09 PM UTC 2024
|
||||||
/* Splits tags into separate divs */
|
/* Splits tags into separate divs */
|
||||||
function splitTagDiv() {
|
function splitTagDiv() {
|
||||||
const header = document.querySelector("header");
|
const header = document.querySelector("header");
|
||||||
if (!header) return;
|
if (!header) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const split = `{{Focus}} {{Tags}}`.split(" ");
|
const split = `{{Focus}} {{Tags}}`.split(" ");
|
||||||
const dont_show = ["imageonfront", "tolearn", "marked"];
|
const dont_show = ["imageonfront", "tolearn", "marked"];
|
||||||
|
|
||||||
|
@ -152,10 +157,7 @@ Wed Feb 7 08:30:09 PM UTC 2024
|
||||||
}
|
}
|
||||||
|
|
||||||
function isMobile() {
|
function isMobile() {
|
||||||
return document
|
return document.getElementsByTagName("html")[0].classList.contains("mobile");
|
||||||
.getElementsByTagName("html")[0]
|
|
||||||
.classList
|
|
||||||
.contains("mobile");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If a card has the "imageonfront" tag set, show images on the front side. */
|
/* If a card has the "imageonfront" tag set, show images on the front side. */
|
||||||
|
@ -174,9 +176,31 @@ Wed Feb 7 08:30:09 PM UTC 2024
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggle_jp1k_furigana() {
|
||||||
|
for (const element of document.querySelectorAll("#jp1k-tsc ruby rt")) {
|
||||||
|
element.style.visibility = !element.style.visibility ? "visible" : "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleJP1KMode() {
|
||||||
|
const tsc_el = document.querySelector("#tsc");
|
||||||
|
const jp1k_el = document.querySelector("#jp1k-tsc");
|
||||||
|
const is_jp1k_mode = `{{Tags}}`.split(" ").includes("jp1k");
|
||||||
|
jp1k_el.setAttribute("visible", is_jp1k_mode);
|
||||||
|
tsc_el.setAttribute("visible", !is_jp1k_mode);
|
||||||
|
}
|
||||||
|
|
||||||
markPitch();
|
markPitch();
|
||||||
splitTagDiv();
|
splitTagDiv();
|
||||||
reformatMultiFurigana();
|
reformatMultiFurigana();
|
||||||
setVisibleImageOnFront();
|
setVisibleImageOnFront();
|
||||||
toggleImageDetails();
|
toggleImageDetails();
|
||||||
|
toggleJP1KMode();
|
||||||
|
document.addEventListener("keydown", (event) => {
|
||||||
|
/* Press "P" to reveal furigana for all words */
|
||||||
|
const P_KEY = 80;
|
||||||
|
if (event.keyCode === P_KEY) {
|
||||||
|
toggle_jp1k_furigana();
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -168,6 +168,10 @@ header>div:not(:last-child) {
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
flex-flow: column nowrap;
|
flex-flow: column nowrap;
|
||||||
}
|
}
|
||||||
|
.sent-center:where(#tsc, #jp1k-tsc):not([visible="true"]) {
|
||||||
|
/* toggles between JP1K mode and regular TSC mode. */
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
/* Japanese sentence */
|
/* Japanese sentence */
|
||||||
|
|
||||||
|
@ -650,3 +654,33 @@ summary {
|
||||||
content: "; ";
|
content: "; ";
|
||||||
color: #f6a192;
|
color: #f6a192;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Toggle furigana button - JP1K mode */
|
||||||
|
|
||||||
|
.toggle_furigana_button {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: bold;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 8px 4px;
|
||||||
|
border-radius: 4px;
|
||||||
|
background-color: #333;
|
||||||
|
color: #fffaf0;
|
||||||
|
border: 0;
|
||||||
|
outline: 0;
|
||||||
|
margin: 0 0 6px;
|
||||||
|
}
|
||||||
|
.toggle_furigana_button:hover,
|
||||||
|
.toggle_furigana_button:active {
|
||||||
|
background-color: #4f4f4f;
|
||||||
|
background: #4f4f4f;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hidden furigana on front - JP1K mode */
|
||||||
|
|
||||||
|
#jp1k-tsc ruby rt {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
#jp1k-tsc ruby:hover rt {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
Loading…
Reference in a new issue