Created
December 31, 2015 22:27
-
-
Save gajewsk2/b544f57c9c81c64f3e5a to your computer and use it in GitHub Desktop.
JS Snippet to toggle furigana in anki
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="reading front"> | |
<a href="http://jisho.org/search/{{text:kanji:Reading}}"> | |
<span id="expression-content">{{kanji:Reading}}</span> | |
<span class="hidden" id="reading-content">{{furigana:Reading}}</span> | |
</a> | |
</div> | |
<div class="dim">{{Notes}}</div> | |
<script> | |
function linkHit (e) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
reading.classList.remove('hidden'); | |
expression.classList.add('hidden'); | |
} | |
//CHANGE ID HERE IF YOU WANT TO CALL YOUR'S SOMETHING ELSE | |
var reading = document.getElementById("reading-content"); | |
var expression = document.getElementById('expression-content'); | |
var clicked = false; | |
expression.addEventListener('click', function(e){ | |
if (reading.innerText !== expression.innerText && !clicked) { | |
clicked = true; | |
linkHit(e); | |
} | |
}); | |
document.addEventListener('keydown', function(e) { | |
//CHANGE KEYCODE TO TOGGLE FURIGANA | |
if(e.keyCode === 96){ | |
linkHit(e); | |
} | |
}); | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.hidden{ | |
display: none; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment