I am currently working on a program, which collects a large set of example sentences for a particular word to create anki flashcards out of. When reviewing the cards, I found that it would be nice if one was able to permanently “mark” a sentence that was particularly useful or suitable for remembering the word with, so that subsequent reviews of this flashcard make it easier to find those particular sentences. Right now, I am simply generating a nested list of <detail> html objects. I tried coming up with some javascript that e.g. permanently changes the default state of those collapsibles, or maybe a sort of “checkbox” that can be ticked to make it more visible in the future, but as far as I see, at the moment nothing can permanently edit the underlying html without entering “edit” mode.
Is there a way to permanently change the underlying data of a flashcard without using the “edit” functionality?
Not with pure JavaScript, some kind of a bridging add-on will have to be made to catch signals from card scripts and make respective changes to the database.
I suppose localStorage can be utilized to store states based on some kind of card hash, but this likely won’t be as reliable as changes to the database and won’t sync between different devices or persist through Anki updates.
@Eltaurus I see. As far as I know addons are only available for the desktop app, can you think of any way that users on e.g. ankidroid would be able to persistently modify the card content directly via the flashcard javascript?
If not, do you think it would be meaningful to propose or submit a PR for this kind of change to the Anki/Ankidroid repository, or is there maybe an aspect that has not been mentioned yet as to why this might not be such a good idea?
AnkiDroid has its own JS API that provides some functionality unavailable on other platforms. I don’t think it has the capability to modify card data though, but I don’t follow its development closely, so you might want to take a look in case I’m missing something or the doc is incomplete.
AnkiMobile, on the other hand, is likely to be completely out of the question in this regard.
As far as I’m aware, API PRs are not very likely to get accepted at this point[1][2][3]. Especially the functionality that involves access to the database for the security risks involved[4].
There is a very hacky way to store data using AnkiDroid’s JS API: you can get and set tags so you can use them to store data and modify the card using JS.
I’ve been doing quite a bit of this recently, and it’s been very effective. It doesn’t persist between devices, but the data hasn’t reset in nearly a year of use. You’ll need to turn on localStorage in Settings>Advanced. I made a hash based on card data, but since then I found out about these:
AnkiJS.ankiGetCardId(): Retrieves the ID of the current card.
AnkiJS.ankiGetCardNid(): Retrieves the Note ID of the current card.
AnkiJS.ankiGetCardDid(): Retrieves the Deck ID of the current card.
Yeah I also looked into using localStorage, interesting approach But I think for the usecase outlined in this thread it would make more sense to find a way that allows for syncing with the anki database, which is most likely only possible by utilizing (or “misusing”) the card tagging functionality by writing and reading the marking data for the different sentences in a custom format
I tried following your approach, and it works well on anki desktop so far. However, in ankidroid, there seems to be an issue when reading tags. If I understand correctly, we should be using ankiconnect to read the available tags from the deck in the javascript, and then look for the ones that are specific to our own current card, which is done via ankiconnect in anki desktop, right? And for ankidroid, do we need to manually activate the javascript api in the settings to allow for the same workflow, or am I missing something fundamental that would make this whole thing easier?