Modifying card notes, without saving it to database


I already opened same thread, but it was about JS templates, and now about addons.

I want to modify card’s fields, without saving it to database. So, for example, a user will see word in Browse window, but will also see the word while learning.

Firstly I looked at hooks list, and saw there card_will_show hook, but it allows modifying HTML. When I looked at card argument, that this hook accepts, I saw that I can access card fields with card.note()["Field name"], and even modify it! Unfortunately it will not work with just card.note()["Field name"] = "value", Anki anyway shows old value, and it didn’t save anything. If I do card.note().flush(), it will save new value to the database (which I don’t want) and render old value, which is really strange.

I could make some kind of compilation step, which will fetch all cards and modify their values with saving it to database on Anki start, but it too many code and logic for my goal. If there is no way to do what I want, I will do this.

Any help is welcome! Thanks!

It sounds to me that such modification is achievable through javascript in your html templates.
Imagine for example that you have a field Description and you want to display it in UPPERCASE letters. In this case you can do the following in your html template

<span id="uppercase-description">{{Description}}</span>

const descriptionElement = $("titlecase-description")
const normalDescription =descriptionElement.text();
const upperCaseDescription = normalDescription.toUpperCase();

The following will happen. If for certain card the Description field was “My awesome description”, you will see “MY AWESOME DESCRIPTION”

It’s also possible to allow user to modify the content on the card without saving it to the database. For that you will need to have a form field prepopulated from the card field. As soon as you go to the next card, the changes are gone.

I already tried to do this, but JS can’t modify values in a way, that code will understand.

Like {{type:...}}. It will understand only lowercased variant. Or AwesomeTTS addon, it will also use only lowercased variant.

Could you please reference more details, so I can found it in sources/docs? Attribute in object will be enough.

If your goal is to change the text shown during review, it sounds like you want a field filter.

Yes, it really looks like what I’m looking for, but it will work on rendering time, so addons, like TTS ones, will not see it (the same as {{type:...}}).

TTS may see the changes if you use the new format mentioned on Changes in 2.1.50 to 59 - Changes

It could be useful, but addon most likely will not implement it, as it’s many code changes and/or breaking changes. Plus what about {{type:...}}?