So I got this code from an AI wanting to display the cloze hint for my cloze cards in a separate space on my reviewer. There is indeed a new window in my reviewer created…and that was as far as the AI got.
In theory, the code should work but I don’t know what is the problem and what even the problem is or whether it is even possible in the first place.
<script>
// Get the cloze deletion text
let clozeText = "{{cloze:Text}}";
// Extract the hint from the cloze deletion text
let hint = clozeText.split("::")[2];
// If there is a hint, display it in the hint window
if (hint) {
document.getElementById("hint-window").innerText = hint;
}
</script>
<div id="hint-window"></diV>
Yup, I too always think that way in my development.
This code does not seem to show another window on my device.
Perhaps you may want to look for similar code for reference before using AI.
(e.g., a template for displaying windows, a template for displaying hints, etc.)
I have put this into Gemini to try and modify it and it came up with this but it did not work. I am now trying to get it to work with the Edit during Cloze addon .
<script>
if (document.querySelector(".cloze").textContent != "[...]") {
const clozeText = document.querySelector(".cloze").textContent;
const hintText = formatHint(clozeText);
document.getElementById("hint-div").innerHTML = `
<input
type="text"
value="${hintText}"
style="border: 1px solid white; color: white; background-color: black; padding: 2px 5px;"
oninput="updateClozeHint(this.value)"
onchange="saveClozeHint(this.value)"
>
`;
}
function formatHint(str) {
return str.slice(1, -1); // Extract hint text
}
function updateClozeHint(newHint) {
// Update the visual hint immediately in the input box
document.getElementById("hint-div").querySelector("input").value = newHint;
// Logic to communicate with Edit Cloze During Review add-on
// (See next section)
}
function saveClozeHint(newHint) {
// Save the hint permanently within the Anki card
// (See next section)
}
</script>
do you have any idea how this code could work with the Edit Cloze during Review addon
Problem with this is Anki keeps recognising c\d+::.+? as a field so it shows the error Found c\d+::.+?, but there is no c\d+::.+?
This is another version of the code, which actually allows for some editing, but if you try it out, the edit resets once you close the card
<div id="hint-div" style="position: fixed; top: 0; left: 50%; transform: translateX(-50%);"></div>
<script>
if (document.querySelector(".cloze").textContent != "[...]") {
const clozeText = document.querySelector(".cloze").textContent;
const hintText = formatHint(clozeText);
document.getElementById("hint-div").innerHTML = `
<input
type="text"
value="${hintText}"
style="border: 1px solid white; color: white; background-color: black; padding: 2px 5px;"
oninput="updateClozeHint(this.value)"
onchange="saveClozeHint(this.value)"
>
`;
}
function formatHint(str) {
return str.slice(1, -1); // Extract hint text
}
function updateClozeHint(newHint) {
// Update the visual hint immediately in the input box
document.getElementById("hint-div").querySelector("input").value = newHint;
// Logic to communicate with Edit Cloze During Review add-on
// (See next section)
}
function saveClozeHint(newHint) {
// Save the hint permanently within the Anki card
// (See next section)
}
</script>