Skip to content

Instantly share code, notes, and snippets.

@chriskempson
Last active April 1, 2022 20:33
Show Gist options
  • Save chriskempson/aa045b8cd73ab8442f0b0d48b755fd5d to your computer and use it in GitHub Desktop.
Save chriskempson/aa045b8cd73ab8442f0b0d48b755fd5d to your computer and use it in GitHub Desktop.
Hidy ruby text (furigana) on Anki cards by default, touch or click to reveal ruby text.
// Paste this code at the bottom of your front template or back tempate (or
// both) and add a class="toggle-furigana" to an element to furigana text
// until clicked/touched. Afterwards, furigana will automatically be hidden
<script>for(var toggleRubyElements=document.getElementsByClassName("toggle-furigana"),i=0;i<toggleRubyElements.length;i++)for(var rubyElements=toggleRubyElements[i].getElementsByTagName("ruby"),j=0;j<rubyElements.length;j++){var rt=rubyElements[j].getElementsByTagName("rt")[0];rt.style.visibility="hidden",rubyElements[j].onclick=function(e){toggleRubyText(e.target)}}function toggleRubyText(e){var t=e.parentNode.getElementsByTagName("rt")[0];"hidden"==t.style.visibility?(t.style.visibility="visible",setTimeout(function(){t.style.visibility="hidden"},2e3)):t.style.visibility="hidden"}</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment