I want to modify the preview of a card by injecting some HTML code in it with a hook, just after the question or the answer are rendered.
I found hooks to do this in the reviewer (reviewer_did_show_question and reviewer_did_answer_card, used reviewer.web.eval(script) to inject my code) but I can’t find anything similar for the previewer.
Wrapping Previewer.render_card or Browser._renderPreview did not work.
I’m using Anki 2.1.35 by the way.
Which hook should I be using, or which method should I wrap ?
Thank you in advance !
def on_webview_will_set_content(web_content, context):
if not isinstance(context, aqt.previewer.Previewer):
# not previewer, do nothing
return
# do something
The ts and card.nid do not change when I switch from one card to the next, or when I reveal the answer.
Sorry I should have specified it before, but my addon displays a graph (computed with Python code) that depends on the card, and it also changes between the question and answer.
Is there a way to do this ?
As a last resort, maybe rewriting the computation in javascript would work ?