I’m currently experimenting with customizing the card templates and am trying to go a bit beyond basic HTML/CSS. Specifically, I’d like to create a user-triggered action that combines or builds upon existing functionalities like calling Anki’s “Undo” or “Pause” actions from within the card’s script section.
Is it possible to access these built-in commands (Mostly Undo) from the card’s JavaScript area? I’ve looked into the official documentation but haven’t seen anything conclusive about interacting with those core functionalities directly from the card interface.
The AnkiDroid JavaScript API offers some advanced possibilities, although i’m not sure if it includes undo. And it is a ankidroid-specific feature, so by itself it won’t work across plattforms.
There is this addon, which offers some of the same functionality. But i haven’t tested it myself and am not sure if it works. See e.g. this thread.
That’s really interesting! I’ll definitely keep the AnkiDroid JavaScript API in mind, especially when I eventually start looking into ways to run Anki on a smart TV. For now though, I mostly use Anki on PC and AnkiMobile for iOS, so I’m hoping to find something a bit more cross-platform or desktop/iOS-compatible.
Also, I noticed the link to the addon seems to be broken. If you happen to have an updated one or the name of the addon, I’d love to take a look.
Sorry i’ve botched the link, it should work now.
Apparently you can also call some python functions via a pycmd
function from JS, but i’ve not tried this out. See this other thread. It seems to be more geared towards addons, but maybe you could try using this just from your JS template.
Before investing loads of time in either of these, remember that these are some pretty advanced features which are (probably intentionally) not widely advertised by the developers. There is no guarantee, that these APIs will stay the same in the future, so if you rely on them, your code might break in the future and you might have to rewrite it.
That beeing said, i’ve written some JS templates myself to do some random things which i wanted to have, and it can be a lot of fun
It’s also motivating because you are ‘scratching your own itch’. So by no means feel discouraged by the previous point. Just maybe don’t expect your code to work exactly the same 5 years from now.
Cheers!
2 Likes
Thanks again. This has all been really helpful!
So far, the only pycmd
command I’ve been able to get working is pycmd('ans')
. I haven’t found a list of other built-in commands anywhere. If anyone knows of others or where they might be documented, I’d really appreciate the info.
I’ve also started looking into AnkiConnect - AnkiWeb since it’s actively maintained and well-documented. Do you think it could be used to trigger actions like undo or pause from within a card’s JavaScript?
Thanks again for all the help. This has been really fun to dig into!
What actions are you trying to undo exactly?
Good question. Right now I’m mostly looking at undoing answers, like what happens when you press “Undo” right after answering a question. Keeping the full functionality of a Ctrl+Z-style undo would be nice too, but that’s more of a bonus.