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?