Trigger "Show Answer"/flipToBack in javascript

UPDATE

I bought the template the has this function built-in from the the original author, and it cannot be used separately from the template because of the js being obfuscated.

It is permissible to deobfuscate the js and keep it for personal use according to the CC BY-NC-ND 4.0 DEED, but given the fact that the author claimed to have the capacity to de-activate users if the number of the active devices are beyond limit, it might not be encouraged.

I am sorry that I cannot distribute the js because the author specified in the blog that he didn’t want the buyers to distribute the template.

FYI, the blog is in Chinese, and I think the payment method is not widely used by anyone outside of Mainland China, so if you are interested in the project, for personal or commercial usage, you could also find the author on Github.

OP

I found this script but unfortunately it stopped working after ankimobile 2.0.81, and now i am wondering if there is a way to make this work on ankimobile again.

Here is the script:

// flipToBack reference to https://github.com/git9527/anki-awesome-select
function flipToBack() {
	if (typeof pycmd !== "undefined") {
		pycmd("ans")
	} else if (typeof study !== "undefined") {
		study.drawAnswer()
	} else if (typeof AnkiDroidJS !== "undefined") {
		showAnswer()
	} else if (window.anki && window.sendMessage2) {
		window.sendMessage2("ankitap", "midCenter")
	}
}

Here is the code to ankimobile 2.0.88 just in case someone wants to check it out.

1 Like

@dae would it perhaps be feasible to expose an AnkiDroid-like showAnswer API on AnkiMobile and AnkiWeb? This would be very useful for any templates that validate user input (e.g. multiple choice, custom type-the-answer implementations), or templates that are one-sided.

Personally struggled with this in the past when creating a multiple choice notetype, and have seen this come up a few times now:

1 Like

Please note these are private APIs, and they may change/break at any time. The AnkiWeb one is probably already broken.

I’m unsure about exposing this functionality publicly, as I can imagine scenarios such as a deck author deciding that the answer should automatically show after 5 seconds, and then confused users will end up writing in here.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.