Closet For Anki [Official support]

Update 02.08.21: This should work with arbitrary card indices.

I don’t know why closetPromise.then() didn’t work when I first tried it, but it seems to work reliably now that I’ve tried it again. The following script has to be inserted into the Closet setup, but only on the front template (check out the sample note type with Asset Manager to see how I did that with an HTML snippet):

closetPromise.then(() => {

    if ((rect = document.querySelector(".closet-rect.is-active")) != null) incrementalIO(rect)

    function incrementalIO(first) {
        for (rect of document.querySelectorAll(".closet-rect.is-active")) {
            rect.classList.remove("is-active")
        }
        activate(first)
    }

    function activate(rect) {
        rect.classList.add("is-active")
        rect.addEventListener("click", reveal)
    }

    function reveal() {
        this.classList.remove("is-front")
        this.classList.add("is-back")
        if ((next = this.nextElementSibling) != null) {
            activate(next)
        }
    }
})
How to create the notes

While adding new occlusion rectangles, hold Alt to keep the index at 1. That way only one card will be created.

e.g.:

[#!occlusions [[rect1::141,197,360,92]]
[[rect1::326,484,175,88]]
[[rect1::263,781,282,63]]
[[rect1::725,540,302,71]]
[[rect1::772,190,348,58]]
[[rect2::29,416,68,241]]
[[rect2::107,886,275,56]]
[[rect2::458,886,321,54]]
[[rect2::1044,884,114,49]]
[[rect3::392,34,453,63]] #]

Showcase

Kooha-2021-07-18-14_21_02


Update 02.08.21: Keeping this question here for legacy purposes
@hengiesel I would love to know how to execute scripts like this one directly after Closet. Is there a way to access a promise and use .then()? Using setTimeout() feels hacky :slight_smile:

1 Like