reformat file
This commit is contained in:
parent
a009fc232f
commit
5c352cc4c3
|
@ -30,7 +30,7 @@ Wed Feb 7 08:30:09 PM UTC 2024
|
|||
{{/Image}}
|
||||
</div> <!-- /wrap -->
|
||||
|
||||
<div style="display:none;">
|
||||
<div style="display: none">
|
||||
<div id="vocab_kanji_hidden">{{VocabKanji}}</div>
|
||||
<div id="pitchnum_hidden">{{VocabPitchNum}}</div>
|
||||
<div id="kanaword_hidden">{{kana:VocabFurigana}}</div>
|
||||
|
@ -82,16 +82,16 @@ Wed Feb 7 08:30:09 PM UTC 2024
|
|||
|
||||
function odaka(pitch_num) {
|
||||
// word is odaka if number of moras is equal to pitch accent position
|
||||
const moras = document.getElementById("kanaword_hidden").innerText
|
||||
.replace(/[((<].*[>))]/, "") // remove (お), (する), <する>, <な>, etc
|
||||
const moras = document
|
||||
.getElementById("kanaword_hidden")
|
||||
.innerText.replace(/[((<].*[>))]/, "") // remove (お), (する), <する>, <な>, etc
|
||||
.replace(/[ャュョゃゅょ]/g, "") // small っ is one mora; ゃゅょ are parts of single mora
|
||||
.trim();
|
||||
// first determine if な is part of pronunciation or な-adjective (e.g. 女)
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
/* Splits tags into separate divs */
|
||||
|
@ -99,7 +99,7 @@ Wed Feb 7 08:30:09 PM UTC 2024
|
|||
const header = document.querySelector("header");
|
||||
if (!header) return;
|
||||
const split = `{{Focus}} {{Tags}}`.split(" ");
|
||||
const dont_show = ['imageonfront', 'tolearn', 'marked',];
|
||||
const dont_show = ["imageonfront", "tolearn", "marked"];
|
||||
|
||||
header.innerHTML = "";
|
||||
|
||||
|
@ -114,28 +114,31 @@ Wed Feb 7 08:30:09 PM UTC 2024
|
|||
|
||||
function formatNewRuby(kanji, readings) {
|
||||
if (readings.length > 1) {
|
||||
return `<ruby>${formatNewRuby(kanji, readings.slice(0, -1))}</ruby><rt>${readings.slice(-1)}</rt>`
|
||||
return `<ruby>${formatNewRuby(kanji, readings.slice(0, -1))}</ruby><rt>${readings.slice(-1)}</rt>`;
|
||||
} else {
|
||||
return `<rb>${kanji}</rb><rt>${readings.join('')}</rt>`
|
||||
return `<rb>${kanji}</rb><rt>${readings.join("")}</rt>`;
|
||||
}
|
||||
}
|
||||
|
||||
function reformatMultiFurigana() {
|
||||
const separators = /[\s;,.、・。]+/iu;
|
||||
const max_inline = 2;
|
||||
document.querySelectorAll("ruby:not(ruby ruby)").forEach(ruby => {
|
||||
document.querySelectorAll("ruby:not(ruby ruby)").forEach((ruby) => {
|
||||
try {
|
||||
const kanji = (ruby.querySelector("rb") || ruby.firstChild).textContent.trim();
|
||||
const readings = ruby.querySelector("rt").textContent
|
||||
.split(separators)
|
||||
.map(str => str.trim())
|
||||
.filter(str => str.length);
|
||||
const readings = ruby
|
||||
.querySelector("rt")
|
||||
.textContent.split(separators)
|
||||
.map((str) => str.trim())
|
||||
.filter((str) => str.length);
|
||||
|
||||
if (readings.length > 1) {
|
||||
ruby.innerHTML = formatNewRuby(kanji, readings.slice(0, max_inline));
|
||||
}
|
||||
if (readings.length > max_inline) {
|
||||
const sequence = readings.map(reading => `<span class="tooltip-reading">${reading}</span>`).join('');
|
||||
const sequence = readings
|
||||
.map((reading) => `<span class="tooltip-reading">${reading}</span>`)
|
||||
.join("");
|
||||
const wrapper = document.createElement("span");
|
||||
wrapper.classList.add("tooltip");
|
||||
wrapper.innerHTML += `<span class="tooltip-text">${sequence}</span>`;
|
||||
|
@ -145,7 +148,7 @@ Wed Feb 7 08:30:09 PM UTC 2024
|
|||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function isMobile() {
|
||||
|
|
Loading…
Reference in a new issue