Javascript in AnkiDroid?

664 views
Skip to first unread message

someguy

unread,
Jul 4, 2013, 3:53:17 PM7/4/13
to anki-a...@googlegroups.com
I had an idea to add a timer to a shared deck using javascript. Someone told me on the Anki-Users forum that AnkiDroid may be problematic in this regard.

Basically, what I want to do is:

====>>>>
1. Detect the question-side of card by the *absence* of "hr id=answer".
1.2. Start a timer with:

     var elapsedTime = 0;

     var myTimer = setInterval(incrementTimer, 200);


2. Otherwise, it's the answer-side of card
2.2. Stop timer and write the elapsed time to the element on the card:

    window.clearInterval(myTimer)
    document.getElementById("timer").innerHTML = elapsedTime
<<<<====

This words perfectly with Anki desktop. However, someone said AnkiDroid can't do this. Something about a flip of the card being treated like a new card (creating a new environment).

My questions are:

1. Will this work on AnkiDroid?
2. If not, is there another way to pass the incremented timer value? (I googled and read something about get/set properties on Droid?).

I wanted to stay away from addons since this seemed like such a simple feature (especially when implemented within an environment using webkit).

Thanks.

Houssam Salem

unread,
Jul 24, 2013, 8:29:12 AM7/24/13
to anki-a...@googlegroups.com
Sorry for the late reply. As I mentioned on the Anki forum, no, this unfortunately won't work. For some reason, we're using a new WebView for each side of the card, so you can't keep data around between flips. Either this was a workaround for an old issue I'm not aware of or it's a holdover from the AnkiDroid 1 days. The reviewer code wasn't rewritten for AnkiDroid 2 and could use a bit of a cleanup.

This is something that I want as well, so I might look into it in the future, but we have other priorities at the moment. Don't hold your breath.

Flavio Lerda

unread,
Jul 24, 2013, 9:06:55 AM7/24/13
to anki-a...@googlegroups.com
The reason for replacing the WebView was that there used to be a leak in the code that handles @font-face in its implementation.
Replacing the view solved that issue.

Even before that though, the content of the WebView has always been reloaded from scratch, which means any of the state would
be lost.

The issue above is (I believe) fixed in ICS+ (and there is now a setting in the preferences to disable the workaround).

Changing the behavior to not reload the WebView content is something that would need to be implemented.

Flavio


--
You received this message because you are subscribed to the Google Groups "AnkiDroid" group.
To unsubscribe from this group and stop receiving emails from it, send an email to anki-android...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Flavio Lerda
Reply all
Reply to author
Forward
0 new messages