RisingOrange / anki-enhanced-cloze

20 stars 4 forks source link

User action in iOS Anki. #65

Closed ParkJaeseoCom closed 1 year ago

ParkJaeseoCom commented 1 year ago

Hi. I'm using enhanced Cloze in Mac and iOS. iOS Anki supports User Action function.

In Anki Manual, : To define a user action, you must know the function the card template provides. If you know it provides a revealNext() function for example, you can tell AnkiMobile to call it with the following code: var userJs1 = revealNext;

I'm trying to use this function with enhanced Cloze.

I enter the code 'var userJs1 = revealOneClozeOfAType; but it doesn't work.

Is there anyone who knows how to work?

RisingOrange commented 1 year ago

One of these should work for you:

var userJs1 = () => revealOneClozeOfAType("genuine")

This will reveal the next red cloze.

var userJs1 = () => revealOneClozeOfAType("pseudo")

This will reveal the next blue cloze.

ParkJaeseoCom commented 1 year ago

@RisingOrange Thanks for reply. I copy that code in the front card template, but there is error with the message

"ReferenceError : Can't find variable: revealOneClozeOfAType"

Is there any adequate place to put that code in? I place that code next to the shortcut script.

anki-cat commented 1 year ago

Have you found a solution yet? I also have the same problem

anki-cat commented 1 year ago

With the help of the big shots, my problem has been solved. Please go to the website: https://forums.ankiweb.net/t/how-can-i-use-user-action-by-configuring-javascript/31144

ParkJaeseoCom commented 1 year ago

With the help of the big shots, my problem has been solved. Please go to the website: https://forums.ankiweb.net/t/how-can-i-use-user-action-by-configuring-javascript/31144

can you please share me a code? function revealOneClozeOfAType(clozeType) { if (!["genuine", "pseudo"].includes(clozeType)) { console.log(clozeType has unexpected value: ${clozeType}`) }

        if (!$(`.${clozeType}-cloze[show-state="hint"]`).length) {
            $('#no-more-cloze').animate({
                display: "toggle",
            }, 500);
            return
        }

        var hiddenClozes = $(`.${clozeType}-cloze[show-state="hint"]`)
        if (hiddenClozes.length != 0) {
            revealCloze(hiddenClozes[0]);
        }
    }, globalThis [“userJs1”] = () => revoalOneClozeOfAType (“genuine”)`

I put like this but it didn't work

anki-cat commented 1 year ago

With the help of the big shots, my problem has been solved. Please go to the website: https://forums.ankiweb.net/t/how-can-i-use-user-action-by-configuring-javascript/31144

can you please share me a code? function revealOneClozeOfAType(clozeType) { if (!["genuine", "pseudo"].includes(clozeType)) { console.log(clozeType has unexpected value: ${clozeType}`) }

        if (!$(`.${clozeType}-cloze[show-state="hint"]`).length) {
            $('#no-more-cloze').animate({
                display: "toggle",
            }, 500);
            return
        }

        var hiddenClozes = $(`.${clozeType}-cloze[show-state="hint"]`)
        if (hiddenClozes.length != 0) {
            revealCloze(hiddenClozes[0]);
        }
    }, globalThis [“userJs1”] = () => revoalOneClozeOfAType (“genuine”)`

I put like this but it didn't work

You can try this setting that I successfully set: (Replace the above code with the following code)

    function revealOneClozeOfAType(clozeType) {
        if (!["genuine", "pseudo"].includes(clozeType)) {
            console.log(`clozeType has unexpected value: ${clozeType}`)
        }

        if (!$(`.${clozeType}-cloze[show-state="hint"]`).length) {
            $('#no-more-cloze').animate({
                display: "toggle",
            }, 500);
            return
        }

        var hiddenClozes = $(`.${clozeType}-cloze[show-state="hint"]`)
        if (hiddenClozes.length != 0) {
            revealCloze(hiddenClozes[0]);
        }
    }
     globalThis["userJs1"] = () => revealOneClozeOfAType("genuine")
ParkJaeseoCom commented 1 year ago

With the help of the big shots, my problem has been solved. Please go to the website: https://forums.ankiweb.net/t/how-can-i-use-user-action-by-configuring-javascript/31144

can you please share me a code? function revealOneClozeOfAType(clozeType) { if (!["genuine", "pseudo"].includes(clozeType)) { console.log(clozeType has unexpected value: ${clozeType}`) }

        if (!$(`.${clozeType}-cloze[show-state="hint"]`).length) {
            $('#no-more-cloze').animate({
                display: "toggle",
            }, 500);
            return
        }

        var hiddenClozes = $(`.${clozeType}-cloze[show-state="hint"]`)
        if (hiddenClozes.length != 0) {
            revealCloze(hiddenClozes[0]);
        }
    }, globalThis [“userJs1”] = () => revoalOneClozeOfAType (“genuine”)`

I put like this but it didn't work

You can try this setting that I successfully set: (Replace the above code with the following code)

    function revealOneClozeOfAType(clozeType) {
        if (!["genuine", "pseudo"].includes(clozeType)) {
            console.log(`clozeType has unexpected value: ${clozeType}`)
        }

        if (!$(`.${clozeType}-cloze[show-state="hint"]`).length) {
            $('#no-more-cloze').animate({
                display: "toggle",
            }, 500);
            return
        }

        var hiddenClozes = $(`.${clozeType}-cloze[show-state="hint"]`)
        if (hiddenClozes.length != 0) {
            revealCloze(hiddenClozes[0]);
        }
    }
   globalThis["userJs1"] = () => revealOneClozeOfAType("genuine")

Thanks! It works! Have a great day!