Enable addon access to v3 scheduling states without monkey-patching

Currently it’s difficult for addons to access/modify the card states in the v3 scheduler.

It’s possible to paste Javascript into the “Custom Scheduling” field in the Deck Options menu, but this isn’t exposed to addons.

While the Reviewer has get_scheduling_states and set_scheduling_states functions, there is no good hook to access them, nor is there any meaningful way to run the Javascript function mutateNextCardStates over an addon-provided Javascript function if one wished to access the scheduling states this way instead. The closest hook is the card_will_show hook but it doesn’t give access to the Reviewer, so it’s useless for this.

The only nearby hook that does give access to the Reviewer object is av_player_will_play_tags, which I think everyone can agree is not the right hook to use for such a thing.

This leaves monkey-patching a portion of the Reviewer as the only way to modify the scheduler states, which is obviously undesirable. A way to modify the scheduling states is essential for addons which wish to change Anki’s scheduling behavior.

It’s not? fsrs4anki helper use the content of custom scheduling to reschedule cards

fsrs4anki’s installation instructions have the user manually copy and paste a large javascript file into the “Custom Scheduling” field of each deck which will use fsrs4anki.

This is a ridiculous install mechanism when Anki already has addon support.

I’m pretty sure custom scheduling is global despite being in the deck options, so you edit it, it applies to every deck options, don’t question me about this design logic(was answered but I forgot)

Huh. It doesn’t have to be by implementation at all, it’s applied in the reviewer during _showQuestion().

It could even be individualized to each card if you wanted it to be, although that probably wouldn’t be that useful.

Clean changes will generally be accepted: Hooks and Filters - Writing Anki Add-ons

One concern here is that it will be confusing to users who enter text in the options screen if that text gets overridden by an add-on. One way to avoid that would be to have the hook mutate the state prior to the JS running, so the user code runs last, and/or display a warning in the deck options screen if any add-ons are using that hook.

Minor note: You can always access the Reviewer object using aqt.mw.reviewer.

2 Likes