2021-11-27 14:58:45 +00:00
|
|
|
|
<!--
|
2024-02-07 20:37:32 +00:00
|
|
|
|
mpvacious cards, version 16.0
|
|
|
|
|
Wed Feb 7 08:30:09 PM UTC 2024
|
2021-11-27 14:58:45 +00:00
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
<div class="wrap">
|
2021-12-25 03:19:58 +00:00
|
|
|
|
<header>
|
2022-10-24 15:41:56 +00:00
|
|
|
|
{{#Focus}}
|
|
|
|
|
<div class="tags">{{Focus}}</div>
|
2024-03-29 10:49:57 +00:00
|
|
|
|
{{/Focus}} {{#Tags}}
|
2021-12-25 03:19:58 +00:00
|
|
|
|
<div class="tags">{{Tags}}</div>
|
|
|
|
|
{{/Tags}}
|
|
|
|
|
</header>
|
2021-11-27 14:58:45 +00:00
|
|
|
|
|
2024-03-29 10:49:57 +00:00
|
|
|
|
<div class="sent-center" id="tsc" visible="true">
|
|
|
|
|
<!-- this tag is hidden on the front. -->
|
2023-07-26 19:44:37 +00:00
|
|
|
|
<div class="jpsentence" lang="ja">
|
2024-03-29 10:49:57 +00:00
|
|
|
|
{{edit:furigana:SentKanji}} {{^SentKanji}}
|
2021-12-25 03:19:58 +00:00
|
|
|
|
<nokana>{{edit:kanji:SentFurigana}}</nokana>
|
|
|
|
|
{{/SentKanji}}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2022-09-12 16:58:13 +00:00
|
|
|
|
|
2024-03-29 10:49:57 +00:00
|
|
|
|
<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>
|
|
|
|
|
|
2023-07-26 19:44:37 +00:00
|
|
|
|
{{#Image}}
|
|
|
|
|
<details class="images-on-front images-details">
|
|
|
|
|
<summary>Image</summary>
|
|
|
|
|
<div class="images">{{Image}}</div>
|
|
|
|
|
</details>
|
|
|
|
|
{{/Image}}
|
2024-03-29 10:49:57 +00:00
|
|
|
|
</div>
|
|
|
|
|
<!-- /wrap -->
|
2021-11-27 14:58:45 +00:00
|
|
|
|
|
2024-02-07 21:05:51 +00:00
|
|
|
|
<div style="display: none">
|
2024-02-07 20:31:26 +00:00
|
|
|
|
<div id="vocab_kanji_hidden">{{VocabKanji}}</div>
|
2021-11-27 14:58:45 +00:00
|
|
|
|
<div id="pitchnum_hidden">{{VocabPitchNum}}</div>
|
|
|
|
|
<div id="kanaword_hidden">{{kana:VocabFurigana}}</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
/* Paints the question word according to its Pitch Accent number.
|
|
|
|
|
* blue for 平板
|
|
|
|
|
* red for 頭高
|
|
|
|
|
* orange for 中高
|
|
|
|
|
* green for 尾高
|
|
|
|
|
*/
|
|
|
|
|
function markPitch() {
|
|
|
|
|
let pitchNumber = document.getElementById("pitchnum_hidden");
|
|
|
|
|
if (pitchNumber === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-03-29 10:49:57 +00:00
|
|
|
|
pitchNumber = pitchNumber.innerHTML.match(/\d/);
|
2021-11-27 14:58:45 +00:00
|
|
|
|
if (pitchNumber === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-03-29 10:49:57 +00:00
|
|
|
|
pitchNumber = Number(pitchNumber);
|
2021-11-27 14:58:45 +00:00
|
|
|
|
/* Then decide what color to use and change font color accordingly. */
|
|
|
|
|
if (pitchNumber == 0) {
|
|
|
|
|
// use blue for 平板
|
|
|
|
|
paintTargetWord("#3366CC");
|
|
|
|
|
} else if (pitchNumber == 1) {
|
|
|
|
|
// use red for 頭高
|
|
|
|
|
paintTargetWord("red");
|
|
|
|
|
} else if (pitchNumber > 1) {
|
2024-03-29 10:49:57 +00:00
|
|
|
|
if (is_odaka(pitchNumber)) {
|
2021-11-27 14:58:45 +00:00
|
|
|
|
// use green for 尾高
|
|
|
|
|
paintTargetWord("green");
|
|
|
|
|
} else {
|
|
|
|
|
// use orange for 中高
|
|
|
|
|
paintTargetWord("#ff6207");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function paintTargetWord(color) {
|
2022-04-18 18:21:56 +00:00
|
|
|
|
for (const word of document.querySelectorAll(".jpsentence b, .jpsentence strong")) {
|
2022-04-17 14:37:06 +00:00
|
|
|
|
word.style.color = color;
|
2021-11-27 14:58:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-29 10:49:57 +00:00
|
|
|
|
function is_odaka(pitch_num) {
|
2021-11-27 14:58:45 +00:00
|
|
|
|
// word is odaka if number of moras is equal to pitch accent position
|
2024-02-07 21:05:51 +00:00
|
|
|
|
const moras = document
|
|
|
|
|
.getElementById("kanaword_hidden")
|
|
|
|
|
.innerText.replace(/[((<].*[>))]/, "") // remove (お), (する), <する>, <な>, etc
|
2024-02-07 20:09:14 +00:00
|
|
|
|
.replace(/[ャュョゃゅょ]/g, "") // small っ is one mora; ゃゅょ are parts of single mora
|
|
|
|
|
.trim();
|
|
|
|
|
// first determine if な is part of pronunciation or な-adjective (e.g. 女)
|
2024-02-07 21:05:51 +00:00
|
|
|
|
const vocab_kanji = document.getElementById("vocab_kanji_hidden").innerText.trim();
|
|
|
|
|
// な-adjectives don't change pitch
|
|
|
|
|
const n_moras = /な$/.test(vocab_kanji) ? moras.replace(/な$/, "").length : moras.length;
|
|
|
|
|
return n_moras == pitch_num;
|
2021-11-27 14:58:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Splits tags into separate divs */
|
|
|
|
|
function splitTagDiv() {
|
|
|
|
|
const header = document.querySelector("header");
|
2024-03-29 10:49:57 +00:00
|
|
|
|
if (!header) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-10-24 15:41:56 +00:00
|
|
|
|
const split = `{{Focus}} {{Tags}}`.split(" ");
|
2024-02-07 21:05:51 +00:00
|
|
|
|
const dont_show = ["imageonfront", "tolearn", "marked"];
|
2021-11-27 14:58:45 +00:00
|
|
|
|
|
|
|
|
|
header.innerHTML = "";
|
|
|
|
|
|
|
|
|
|
for (const tag of split) {
|
2022-11-02 19:02:10 +00:00
|
|
|
|
if (tag.length < 1 || dont_show.includes(tag)) continue;
|
2021-11-27 14:58:45 +00:00
|
|
|
|
const tag_elem = document.createElement("div");
|
|
|
|
|
tag_elem.className = "tags";
|
2022-09-12 16:58:13 +00:00
|
|
|
|
tag_elem.innerText = tag;
|
2021-11-27 14:58:45 +00:00
|
|
|
|
header.appendChild(tag_elem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-05 00:08:35 +00:00
|
|
|
|
function formatNewRuby(kanji, readings) {
|
|
|
|
|
if (readings.length > 1) {
|
2024-02-07 21:05:51 +00:00
|
|
|
|
return `<ruby>${formatNewRuby(kanji, readings.slice(0, -1))}</ruby><rt>${readings.slice(-1)}</rt>`;
|
2023-03-05 00:08:35 +00:00
|
|
|
|
} else {
|
2024-02-07 21:05:51 +00:00
|
|
|
|
return `<rb>${kanji}</rb><rt>${readings.join("")}</rt>`;
|
2023-03-05 00:08:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function reformatMultiFurigana() {
|
2023-03-05 00:48:00 +00:00
|
|
|
|
const separators = /[\s;,.、・。]+/iu;
|
2023-07-26 19:44:37 +00:00
|
|
|
|
const max_inline = 2;
|
2024-02-07 21:05:51 +00:00
|
|
|
|
document.querySelectorAll("ruby:not(ruby ruby)").forEach((ruby) => {
|
2023-03-05 00:48:00 +00:00
|
|
|
|
try {
|
2023-07-26 19:44:37 +00:00
|
|
|
|
const kanji = (ruby.querySelector("rb") || ruby.firstChild).textContent.trim();
|
2024-02-07 21:05:51 +00:00
|
|
|
|
const readings = ruby
|
|
|
|
|
.querySelector("rt")
|
|
|
|
|
.textContent.split(separators)
|
|
|
|
|
.map((str) => str.trim())
|
|
|
|
|
.filter((str) => str.length);
|
2023-07-26 19:44:37 +00:00
|
|
|
|
|
2023-03-05 00:48:00 +00:00
|
|
|
|
if (readings.length > 1) {
|
2023-07-26 19:44:37 +00:00
|
|
|
|
ruby.innerHTML = formatNewRuby(kanji, readings.slice(0, max_inline));
|
|
|
|
|
}
|
|
|
|
|
if (readings.length > max_inline) {
|
2024-02-07 21:05:51 +00:00
|
|
|
|
const sequence = readings
|
|
|
|
|
.map((reading) => `<span class="tooltip-reading">${reading}</span>`)
|
|
|
|
|
.join("");
|
2023-07-26 19:44:37 +00:00
|
|
|
|
const wrapper = document.createElement("span");
|
|
|
|
|
wrapper.classList.add("tooltip");
|
|
|
|
|
wrapper.innerHTML += `<span class="tooltip-text">${sequence}</span>`;
|
|
|
|
|
ruby.replaceWith(wrapper);
|
|
|
|
|
wrapper.appendChild(ruby);
|
2023-03-05 00:48:00 +00:00
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
2023-03-05 00:08:35 +00:00
|
|
|
|
}
|
2024-02-07 21:05:51 +00:00
|
|
|
|
});
|
2023-03-05 00:08:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 19:44:37 +00:00
|
|
|
|
function isMobile() {
|
2024-03-29 10:49:57 +00:00
|
|
|
|
return document.getElementsByTagName("html")[0].classList.contains("mobile");
|
2023-07-26 19:44:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If a card has the "imageonfront" tag set, show images on the front side. */
|
|
|
|
|
function setVisibleImageOnFront() {
|
|
|
|
|
if (`{{Tags}}`.split(" ").includes("imageonfront")) {
|
|
|
|
|
for (const frontImg of document.querySelectorAll(".images-on-front")) {
|
|
|
|
|
frontImg.setAttribute("visible", true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Hide images on mobile devices. */
|
|
|
|
|
function toggleImageDetails() {
|
|
|
|
|
for (const detailsElement of document.querySelectorAll(".images-details")) {
|
|
|
|
|
detailsElement.toggleAttribute("open", !isMobile());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-29 10:49:57 +00:00
|
|
|
|
function toggle_jp1k_furigana() {
|
|
|
|
|
for (const element of document.querySelectorAll("#jp1k-tsc ruby rt")) {
|
|
|
|
|
element.style.visibility = !element.style.visibility ? "visible" : "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-29 11:24:39 +00:00
|
|
|
|
function toggle_JP1K_mode() {
|
2024-03-29 10:49:57 +00:00
|
|
|
|
const tsc_el = document.querySelector("#tsc");
|
|
|
|
|
const jp1k_el = document.querySelector("#jp1k-tsc");
|
2024-03-29 11:24:57 +00:00
|
|
|
|
const is_jp1k_mode = `{{Tags}}`.toLowerCase().split(" ").includes("jp1k");
|
2024-03-29 10:49:57 +00:00
|
|
|
|
jp1k_el.setAttribute("visible", is_jp1k_mode);
|
|
|
|
|
tsc_el.setAttribute("visible", !is_jp1k_mode);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 03:19:58 +00:00
|
|
|
|
markPitch();
|
|
|
|
|
splitTagDiv();
|
2023-03-05 00:08:35 +00:00
|
|
|
|
reformatMultiFurigana();
|
2023-07-26 19:44:37 +00:00
|
|
|
|
setVisibleImageOnFront();
|
|
|
|
|
toggleImageDetails();
|
2024-03-29 11:24:39 +00:00
|
|
|
|
toggle_JP1K_mode();
|
2024-03-29 10:49:57 +00:00
|
|
|
|
document.addEventListener("keydown", (event) => {
|
|
|
|
|
/* Press "P" to reveal furigana for all words */
|
|
|
|
|
const P_KEY = 80;
|
|
|
|
|
if (event.keyCode === P_KEY) {
|
|
|
|
|
toggle_jp1k_furigana();
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-07-26 19:44:37 +00:00
|
|
|
|
</script>
|