leoy
December 23, 2024, 2:51pm
7
Yes, the current implementation does not sync between multiple devices.
And as far as I know, it is not possible to modify media files only through card templates.
related links
I encountered the following issues when developing and introducing card templates based on single page applications:
I need to use the storage function to save relevant information about the card,
such as :
the user’s favorite records of field content
Global configuration related to card decks
If such a feature can be supported, combined with user interaction, Anki cards can accomplish many amazing functions.I want to implement a simple function library that can be directly used in template…
opened 06:58PM - 15 Mar 24 UTC
closed 02:49AM - 19 Sep 24 UTC
Bug
Stale
2.17
### Checked for duplicates?
- [X] This issue is not a duplicate
### What a… re the steps to reproduce this bug?
1. Create a card with the following contents on it somewhere:
```html
<script>
const STORAGE_KEY = "example-storage-location";
let existing_storage = localStorage.getItem(STORAGE_KEY);
if (existing_storage === null) {
existing_storage = 0;
} else {
existing_storage = parseInt(existing_storage);
}
console.log("This template has been accessed " + existing_storage + " times.");
existing_storage = existing_storage + 1;
localStorage.setItem(STORAGE_KEY, existing_storage);
console.log(STORAGE_KEY + " set to " + existing_storage);
</script>
```
2. Connect phone in debug mode.
3. Open `chrome://inspect` on phone and check the console logs.
4. Go to front, back, multiple cards, etc.
5. Exit deck to list of decks
6. Select same deck, repeat steps 2-4.
### Expected behaviour
The console should say: "This template has been accessed 0 times", then increment by 1 for each time the template is accessed (once for front, once for back, etc). The number should _not_ reset when you exit and then re-enter the deck.
### Actual behaviour
All localStorage seems to be lost when exiting the deck.
### Debug info
```text
AnkiDroid Version = 2.17.5 (1c1aa94ec466f37d33fd2f75020d9f9021ac811e)
Backend Version = 0.1.34-anki23.12.1 (23.12.1 1a1d4d5419c6b57ef3baf99c9d2d9cf85d36ae0a)
Android Version = 14 (SDK 34)
ProductFlavor = play
Manufacturer = Google
Webview User Agent = Mozilla/5.0 (Linux; Android 14; Pixel 8 Pro Build/UQ1A.240205.004; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/122.0.6261.119 Mobile Safari/537.36
ACRA UUID =
Crash Reports Enabled = true
```
### (Optional) Anything else you want to share?
I have been using `localStorage` to store persistent per-deck settings, e.g. "Show pictures automatically" or "Play TTS automatically", etc, because depending on the review situation, I want more or less automatic behavior (e.g. if I am in a room where I don't have headphones and I need to be quiet, I don't want TTS going off automatically). This worked in previous versions, but now my settings get lost any time I exit the deck.
Seems like [someone else](https://www.reddit.com/r/Anki/comments/1beape6/localstorage_issue_in_ankidroids_latest_version/?rdt=58076) is having the same issue as well, and they appear to be using localStorage to share information across decks.
### Research
- [X] I am reporting a bug specific to AnkiDroid (Android app)
- [X] I have checked the [manual](https://ankidroid.org/docs/manual.html) and the [FAQ](https://github.com/ankidroid/Anki-Android/wiki/FAQ) and could not find a solution to my issue
- [ ] (Optional) I have confirmed the issue is not resolved in the latest alpha release ([instructions](https://docs.ankidroid.org/manual.html#betaTesting))