metropolitan-bronze
metropolitan-bronze6mo ago

Replay only sentence when pressing R

I've been using Migaku's Anki card. I cloned it so I could edit it. Currently when you're on the back of a card, if you press 'R' to replay it first plays the word audio, then the sentence audio and then the word audio again. I want it to play the sentence audio first and then the word audio. Or just not play the word audio at all. I tried removing the word audio from the card completely but doesn't change the result of pressing R. The reason that I want this because I want to listen to the sentence audio multiple times to practice listening to the word in the sentence. I know I can also press the play button next to the sentence, but that's a bit annoying to do and if I'm going to do flashcards every day for years I'd like to make the process as convenient as possible. Is there any way to achieve this? I don't mind getting rid of the Word Audio entirely on the back, but I want to keep it on the front so I can't just empty out that field.
2 Replies
metropolitan-bronze
metropolitan-bronzeOP6mo ago
Created a solution myself. With this script it does what I want when I press Q which also works for me. After a lot of fighting with code that wouldn't work or do things I still don't understand. And some help from chatGPT who doesn't understand what works in Anki very well I made this script. Add it to the back of the card somewhere. I did it at the top but it shouldn't matter where. I did notice scripts breaking when I was coding in other <script> tags so give it it's own script tag to be safe. If you're going to edit it, restart anki after every edit or the previous itteration will still run <script> // If I press Q the keydown event keeps rapid firing until I release Q // I only want it to start the recording once per track so I keep track of if the button has been released yet. var firstTimeSinceQPress = true; // Allow the keydown method to execute again by setting the variable to true after the keyup event document.addEventListener("keyup", function(e) { if (e.key === "q" || e.key === "Q") { firstTimeSinceQPress = true; } }); // Find the first play replaybutton and click it document.addEventListener("keydown", function(e) { if (e.key === "q" || e.key === "Q") { if (firstTimeSinceQPress) { // Find the audio element within the field firstTimeSinceQPress = false; var audioElement = document.querySelector('.soundLink, .replaybutton'); if (audioElement) { // Trigger a click to play the audio audioElement.click(); } else { alert('Audio element not found.'); } } } }); </script>
rival-black
rival-black5mo ago
@Henrik (JST) glad you figured something out!

Did you find this page helpful?