aboutsummaryrefslogtreecommitdiff
path: root/anki-card-temlate/card.js
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-12-29 12:30:30 +0100
committerlonkaars <loek@pipeframe.xyz>2022-12-29 12:30:30 +0100
commitf47d3633c6a54f90acc92d7ccddbf508bf23cc75 (patch)
treee06b2e270871690ef931df2e738a0151afe7069c /anki-card-temlate/card.js
parent2a03e5b1ea0a47ed1ba4d9f7c270588c1b01543d (diff)
typo
Diffstat (limited to 'anki-card-temlate/card.js')
-rw-r--r--anki-card-temlate/card.js70
1 files changed, 0 insertions, 70 deletions
diff --git a/anki-card-temlate/card.js b/anki-card-temlate/card.js
deleted file mode 100644
index 0509c3e..0000000
--- a/anki-card-temlate/card.js
+++ /dev/null
@@ -1,70 +0,0 @@
-function parseSentence(input) {
- var bold = false; // currently bold
- var mode = "normal"; // normal, kanji, reading
- var out = ""; // output html
-
- var alwaysvisisble = false; // if furigana is always visible (on front of card)
- var kanji = ""; // current kanji
- var reading = ""; // current kanji reading
-
- for (var i = 0; i < input.length; i++) {
- // escape characters preceded by \
- if (input[i] == "\\") {
- var escaped = input[i+1];
- if (escaped == "n") escaped = "<br>"; // newline
- out += escaped; i++; continue;
- }
- // parse *test* into <b>test</b>
- if (input[i] == "*") { bold = !bold; out += `<${bold ? "" : "/"}b>`; continue; }
-
- // parse [kanji](reading) into ruby text
- // [kanji](reading) is only visible on card back
- // {kanji}(reading) is always visible
- if (mode == "normal" && input[i] == "[") // hidden reading kanji open
- { kanji = ""; mode = "kanji"; alwaysvisisble = false; continue; }
- if (mode == "normal" && input[i] == "{") // always visible reading kanji open
- { kanji = ""; mode = "kanji"; alwaysvisisble = true; continue; }
- if (mode == "kanji" && input[i] == "]") continue; // hidden reading kanji close
- if (mode == "kanji" && input[i] == "}") continue; // always visible reading kanji close
- if (mode == "kanji" && kanji.length > 0 && input[i] == "(") // reading open
- { reading = ""; mode = "reading"; continue; }
- if (mode == "reading" && input[i] == ")") { // reading close
- mode = "normal";
- out += `<ruby>${kanji}<rt class="${alwaysvisisble ? 'visible' : 'hidden'}">${reading}</rt></ruby>`;
- continue;
- }
-
- // add current character to selected mode buffer
- if (mode == "normal") out += input[i];
- if (mode == "kanji") kanji += input[i];
- if (mode == "reading") reading += input[i];
- }
-
- return out;
-}
-
-function run() {
- // parse all elements with class parse
- for (var el of document.getElementsByClassName("parse")) {
- if (el.classList.contains("parsed")) continue; // ignore already parsed elements
- el.innerHTML = parseSentence(el.innerHTML); // parse
- el.classList.remove("parse"); // mark as parsed
- el.classList.add("parsed");
- }
-
- // toggle spoiler by clicking
- for (var el of document.getElementsByClassName("spoiler")) {
- el.onclick = function () {
- this.classList.toggle("hidden");
- this.classList.toggle("visible");
- };
- }
-
- // remove spoiler from sentence translation if word reading field is empty
- if(document.getElementById("target-word-reading").innerText.length == 0) {
- document.getElementById("sentence-translation").classList.remove("hidden");
- }
-}
-
-run();
-window.onload = () => run();