Last active
April 2, 2023 16:26
-
-
Save BtbN/9928a66a61a41eb6219e4dc8e83cc70f to your computer and use it in GitHub Desktop.
play-all-addon
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
from anki.hooks import wrap | |
from aqt.main import AnkiQt | |
import aqt.sound as aqt_sound | |
import aqt.browser.previewer as aqt_previewer | |
import aqt.reviewer as aqt_reviewer | |
import aqt.clayout as aqt_clayout | |
def my_play_clicked_audio(pycmd, card, _old): | |
play, context, str_idx = pycmd.split(":") | |
if str_idx == "all": | |
if context == "q": | |
tags = card.question_av_tags() | |
else: | |
tags = card.answer_av_tags() | |
aqt_sound.av_player.play_tags(tags) | |
else: | |
return _old(pycmd, card) | |
aqt_sound.play_clicked_audio = wrap(aqt_sound.play_clicked_audio, my_play_clicked_audio, "around") | |
aqt_previewer.play_clicked_audio = aqt_sound.play_clicked_audio | |
aqt_reviewer.play_clicked_audio = aqt_sound.play_clicked_audio | |
aqt_clayout.play_clicked_audio = aqt_sound.play_clicked_audio | |
def leave_marker(self, text, _old): | |
text = _old(self, text) | |
text = text.replace("__IS_PLAY_ALL_AVAILABLE__", "__YES_IT_IS__") | |
return text | |
AnkiQt.prepare_card_text_for_display = wrap(AnkiQt.prepare_card_text_for_display, leave_marker, "around") |
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
<!-- Auto-Play audio --> | |
<script> | |
if ("__IS_PLAY_ALL_AVAILABLE__" === "__YES_IT_IS__") { | |
pycmd('play:a:all'); | |
} else { | |
var audios = document.getElementById('reading-audios'); | |
var delay = 0; | |
for (var i = 0; i < audios.children.length; i++) { | |
setTimeout((ti) => { | |
pycmd('play:a:'+ti); | |
}, delay, i); | |
delay += 2000; | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment