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

**URL:** <https://forums.ankiweb.net/t/keyboard-shortcut-for-a-js-script-is-not-working-in-anki-2-1-41-windows/9367>\
**Category:** Help\
**Created:** [April 18, 2021, 11:28am UTC](https://forums.ankiweb.net/t/keyboard-shortcut-for-a-js-script-is-not-working-in-anki-2-1-41-windows/9367 "2021-04-18T11:28:03Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![shallash](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/shallash/32/4363_2.png) [@shallash](https://forums.ankiweb.net/u/shallash)\
**Post date:** [April 18, 2021, 11:28am UTC](https://forums.ankiweb.net/t/keyboard-shortcut-for-a-js-script-is-not-working-in-anki-2-1-41-windows/9367/1 "2021-04-18T11:28:03Z")

</div>

I had been using the script found in an [AnKing card template](https://www.ankipalace.com/downloadable-content) 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](https://ankiweb.net/shared/info/1642550423).

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](https://www.reddit.com/r/Anki/comments/8e4d9m/make_cloze_open_one_by_one/dxshizl/), 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?

---

<div class="post-metadata">

**Author:** ![shallash](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/shallash/32/4363_2.png) [@shallash](https://forums.ankiweb.net/u/shallash)\
**Post date:** [April 18, 2021, 12:32pm UTC](https://forums.ankiweb.net/t/keyboard-shortcut-for-a-js-script-is-not-working-in-anki-2-1-41-windows/9367/2 "2021-04-18T12:32:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shallash](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/shallash/32/4363_2.png) [@shallash](https://forums.ankiweb.net/u/shallash)\
**Post date:** [April 23, 2021, 1:10am UTC](https://forums.ankiweb.net/t/keyboard-shortcut-for-a-js-script-is-not-working-in-anki-2-1-41-windows/9367/3 "2021-04-23T01:10:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![NickFlint](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/nickflint/32/35471_2.png) [@NickFlint](https://forums.ankiweb.net/u/NickFlint)\
**Post date:** [April 23, 2021, 1:23am UTC](https://forums.ankiweb.net/t/keyboard-shortcut-for-a-js-script-is-not-working-in-anki-2-1-41-windows/9367/4 "2021-04-23T01:23:34Z")

</div>

Try deleting that note type and try the new one at [www.ankingmed.com/downloadable-content](http://www.ankingmed.com/downloadable-content) I recently updated it

---

<div class="post-metadata">

**Author:** ![shallash](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/shallash/32/4363_2.png) [@shallash](https://forums.ankiweb.net/u/shallash)\
**Post date:** [April 23, 2021, 1:37am UTC](https://forums.ankiweb.net/t/keyboard-shortcut-for-a-js-script-is-not-working-in-anki-2-1-41-windows/9367/6 "2021-04-23T01:37:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![NickFlint](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/nickflint/32/35471_2.png) [@NickFlint](https://forums.ankiweb.net/u/NickFlint)\
**Post date:** [April 23, 2021, 1:51am UTC](https://forums.ankiweb.net/t/keyboard-shortcut-for-a-js-script-is-not-working-in-anki-2-1-41-windows/9367/7 "2021-04-23T01:51:12Z")

</div>

You downloaded this file? [AnKingCardTypes.apkg - Google Drive](https://drive.google.com/file/d/1Ka1Mw1P6aldk6pLkJMViiTg-wkNVgrv_/view?usp=drivesdk)

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

---

<div class="post-metadata">

**Author:** ![shallash](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/shallash/32/4363_2.png) [@shallash](https://forums.ankiweb.net/u/shallash)\
**Post date:** [April 23, 2021, 2:29am UTC](https://forums.ankiweb.net/t/keyboard-shortcut-for-a-js-script-is-not-working-in-anki-2-1-41-windows/9367/8 "2021-04-23T02:29:43Z")

</div>

Yes, I did download the card types from the v9 folder, imported em into a fresh anki install, new profile. I first [tried it](https://mega.nz/file/bKwWmJDT#y63T-_2pt6d-iPv9zRKCJffMrTd1_gD4BJz5f7R4hNc) with the Refocus Card addon not installed, and then after installing it too. Still the same issue.

Are you on Windows too?

---

<div class="post-metadata">

**Author:** ![shallash](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/shallash/32/4363_2.png) [@shallash](https://forums.ankiweb.net/u/shallash)\
**Post date:** [April 24, 2021, 5:02pm UTC](https://forums.ankiweb.net/t/keyboard-shortcut-for-a-js-script-is-not-working-in-anki-2-1-41-windows/9367/9 "2021-04-24T17:02:47Z")

</div>

@NickFlint, are you on windows too?

---

<div class="post-metadata">

**Author:** ![NickFlint](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/nickflint/32/35471_2.png) [@NickFlint](https://forums.ankiweb.net/u/NickFlint)\
**Post date:** [April 24, 2021, 5:14pm UTC](https://forums.ankiweb.net/t/keyboard-shortcut-for-a-js-script-is-not-working-in-anki-2-1-41-windows/9367/10 "2021-04-24T17:14:22Z")

</div>

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](https://drive.google.com/file/d/1LJ6Puc-0SNjrVCSYw6Qk3KLVNh5-RB2W/view?usp=sharing)

Try this in a new profile

---

<div class="post-metadata">

**Author:** ![shallash](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/shallash/32/4363_2.png) [@shallash](https://forums.ankiweb.net/u/shallash)\
**Post date:** [April 24, 2021, 5:50pm UTC](https://forums.ankiweb.net/t/keyboard-shortcut-for-a-js-script-is-not-working-in-anki-2-1-41-windows/9367/11 "2021-04-24T17:50:42Z")

</div>

This one is working in 2.1.41 : )

Thank You!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [May 1, 2023, 5:06am UTC](https://forums.ankiweb.net/t/keyboard-shortcut-for-a-js-script-is-not-working-in-anki-2-1-41-windows/9367/12 "2023-05-01T05:06:20Z")

</div>

Closed on May 1, 2023, 5:06am UTC


