Random front of card

Hey all!
Is it possible to randomize having either typing, hearing or seeing the content of a field on the front of a note? Without creating additional types or suspending siblings?

Sure, anything is possible when you believe :rocket:

Front

<div id="tasks">
  <div>{{Front}}</div>
  <div>{{Audio}}</div>
  <div>{{Front}} {{type:Back}}</div>
</div>

<script>
// INSERT ANKI PERSISTENCE SCRIPT HERE
</script>

<script>
if (Persistence.isAvailable()) {
  const max = document.querySelectorAll("#tasks > div").length;
  const i = Math.ceil(Math.random() * max);
  Persistence.setItem("index", i);
  for (let other of document.querySelectorAll(
    `#tasks > div:not(:nth-child(${i})`
  )) {
    other.remove();
  }
}
</script>

Back

<div id="tasks">
  <div>
    {{Front}}
    <hr>
    {{Back}}
  </div>
  <div>
    {{Audio}}
    <hr>
    {{Back}}
  </div>
  <div>
    {{Front}}
    <hr>
    {{type:Back}}
  </div>
</div>

<script>
// INSERT ANKI PERSISTENCE SCRIPT HERE
</script>

<script>
if (Persistence.isAvailable()) {
  for (let other of document.querySelectorAll(
    `#tasks > div:not(:nth-child(${Persistence.getItem("index")})`
  )) {
    other.remove();
  }
}
</script>

Anki Persistence script: https://raw.githubusercontent.com/SimonLammer/anki-persistence/master/script.js

5 Likes

edit: Doesn’t work in the editor, of course…stupid me. Working perfectly while reviewing!! Thanks so much

The front of my card now shows me all the Tasks together, and not randomly. What have I done wrong?

There seems to be a bug or maybe it isn’t possible to do, but audio tags seem to play with all divs. Regardless of which one I currently see. For example if I currently see the Expression field div, which only contains text, it also plays the div which only contains a tts tag. Could it be that this is due to the fact that it’s a {{tts}} on-the-fly tag?

I couldn’t test that yesterday because I don’t have mpv installed, but I thought it would suffice to remove the containing div. There certainly are ways to stop the audio from playing. I’ll get back to you :point_right:t2:

1 Like