Anki Forums

Hint fields show one by one (incremental reveal/uncovering) with hotkey (js only)

There’s the the add-on reviewer hint hotkeys by glutanimate that for “g” reveals all hints at once and for “h” only the next hint. Its source code is here on github. For recent anki versions glutaimate’s add-on needs a small js fix for tts code, see here.

The problem is that this add-on works generally for all note types and has to be installed on each machine. The unhide code is in js and only the key capturing is made with python.

Is there a short pure, basic js solution that works without any add-ons? Kind of like the minimal cloze show one-by-one solution from @kleinerpirat in this thread ? With a pure js solution you could have hint-reveal hotkeys for regular note types and cloze reveal keys for clozes …

To be added to the front template of your cards. You should be able to change the shortcut to whatever you want.

<script>
if (typeof hintClicker_keyUp !== "function") {
  var hintClicker_keyUp = function(e) {
    if (e.key === "h") {
      revealFirstHint();
    } else if (e.key === "g") {
      revealAllHints();
    }
  };
  document.addEventListener("keyup", hintClicker_keyUp, false);
}

function revealFirstHint() {
  var firstHint = document.querySelector("a.hint:not([style])")
  firstHint.click();
}

function revealAllHints() {
  var allHints = document.getElementsByClassName("hint")
  var i;
  for (i = 0; i < allHints.length; i++) {
       allHints[i].click()
  }	
}
</script>
2 Likes

Thank you very much for posting a fully working solution within 30 minutes!

1 Like