diff options
Diffstat (limited to 'card/card.js')
-rw-r--r-- | card/card.js | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/card/card.js b/card/card.js index 347a44c..0509c3e 100644 --- a/card/card.js +++ b/card/card.js @@ -44,14 +44,26 @@ function parseSentence(input) { } function run() { - var input = document.getElementsByClassName("parse"); - - for (var el of input) { - if (el.classList.contains("parsed")) continue; - el.innerHTML = parseSentence(el.innerHTML); - el.classList.remove("parse"); + // 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(); |