Keyboard shortcut for a JS script is not working in Anki 2.1.41 (Windows)

I had been using the script found in an AnKing card template which, when inserted into the back of the card, obscures all active clozes of the same number (by making their immediate background color the same as their font color), except the first cloze in the card. On using the keyboard shortcut, the next obscured cloze is revealed, clicking any obscured cloze also reveals it.

This script worked flawlessly when combined with the Refocus card when reviewing addon.

Since I updated to 2.1.41 from 2.1.35, the keyboard shortcuts no longer work, and only the mouse reveals the clozes. I tried changing the shortcut in the script to see if it was due to a shortcut conflict, but that was not the case. I tried disabling all addons except Refocus card when reviewing, I tried it with all addons disabled; still doesn’t work.

Here is the script:

<script>
var clozes = document.getElementsByClassName("cloze");
var clr = window.getComputedStyle(clozes[0]).color;
var bg = window.getComputedStyle(clozes[0]).background;
for (i=1; i<clozes.length; ++i) {
  clozes[i].style.background = clr;
  clozes[i].onclick = function() {this.style.background=bg ;}
}
</script>

<script>
    const clozes = [...document.querySelectorAll(".cloze")];
    if (clozes.length) {
        const cloze_color = window.getComputedStyle(clozes[0]).color;
        const cloze_bg_color = window.getComputedStyle(clozes[0]).backgroundColor;
        clozes.slice(1).forEach((item) => {
            item.style.backgroundColor = cloze_color;
            item.addEventListener("click", () => {
                item.style.backgroundColor = cloze_bg_color;
            });
        });
//USER CUSTOMIZATION event.key

        document.addEventListener("keydown", (event) => {
            if (event.key == shortcut) {
                clozes.slice(1).some((item) => {
                    if (item.style.backgroundColor != cloze_bg_color) {
                        item.style.backgroundColor = cloze_bg_color;
                        return true;
                    }
                })
            }
        });
    }
</script>

I also tried another script I found on reddit, which seems to be the precursor of the one above:

<script>  
var handled = false,  
 clozes = document.getElementsByClassName("cloze"),
 clr = window.getComputedStyle(clozes[0]).color,
 bg = window.getComputedStyle(clozes[0]).background;
for (i=1; i<clozes.length; ++i) {  
  clozes[i].style.background = clr;
  clozes[i].onclick = function() {
        this.style.background=bg;
        this.style.cursor='text';}
  clozes[i].style.cursor = 'help';
}
document.onkeypress = function(ev){  
if (handled) return false;}  
document.onkeydown = function() {  
for (i=1; i<clozes.length; ++i) {  
 if (event.which==32 && clozes[i].style.background!=bg){
  clozes[i].style.background=bg;handled=true;return false}
 }
 handled=false;return true;
}
window.setTimeout(function(){ window.focus()},0);  
</script>

Here the keyboard shortcut seems to be the Spacebar, but that doesn’t work either.

Anki Version 2.1.41
Windows 10

Any help in modifying the script would be appreciated, I don’t really have any experience with JS.

Also, should I open a issue on GitHub?

I tried downgrading to 2.1.40, and the script is functioning well. But I would like a solution for 2.1.41 as a few important addons work only with that version.

@AnKingMed, could you check this out please. The script I’m talking about is the one found in your Cloze-one-by-one Card Type.

Try deleting that note type and try the new one at www.ankingmed.com/downloadable-content I recently updated it

Just tried that, the problem persists. Both the old and the new card type are functional in Anki 2.1.40, but not in 2.1.40. (The scripts seem to be exactly the same, anyway.)

Should I open a bug report in the Anki GitHub?

You downloaded this file? AnKingCardTypes.apkg - Google Drive

Open it on a new profile and try it. It’s working for me

Yes, I did download the card types from the v9 folder, imported em into a fresh anki install, new profile. I first tried it with the Refocus Card addon not installed, and then after installing it too. Still the same issue.

Are you on Windows too?

@AnKingMed, are you on windows too?

No I’m on Mac.

I just uploaded a working version of just the one-by-one card type: Cloze one-by-one v2.apkg - Google Drive

Try this in a new profile

This one is working in 2.1.41 : )

Thank You!