anki

How to show only one video from multiple videos on Anki Card


I have cards where a back note has multiple sound tags with video files. I want only one of them to be randomly selected and appear on the card. Unfortunately, I haven't been able to do this.


Solution

  • Finally I came up with this solution:

    Front / Back Template

    // "soundLink": Anki desktop | "replaybutton": AnkiDroid
    var buttons = document.querySelectorAll(".soundLink, .replaybutton");
    
    if (buttons) {
      const randomIndex = Math.floor(Math.random() * buttons.length);
      buttons[randomIndex].classList.add("active");
    }
    

    CSS

    .soundLink,
    .replaybutton {
      display: none;
    }
    
    .soundLink.active,
    .replaybutton.active {
      display: inline-block;
    }