How can I change this code I found on Reddit so that it works for the bionic reading of my cloze cards? I couldn’t get them to work with me on my own. The field name is just Text
The addon version painfully lags every time I load up the text, so I figured maybe if the code is embedded in the template it would load up faster.
@Shigeyuki ?
<script>
function bold_letters(word) {
var len = word.length;
if (!(/^[a-zA-Z]+$/.test(word))) {
return 0;
}
if (len<1) {
return 0;
}
if (len<=3) {
return 1;
}
if (len==4) {
return 2;
}
else {
return Math.round(len/2);
}
}
function antibold(word) {
var len = word.length;
return len-bold_letters(word);
}
var text = document.getElementById("Text").innerHTML;
var i = 0;
words = text.split(" ");
final_str = ""
while (i<words.length) {
if(bold_letters(words[i])==0) {
final_str = final_str + " " + words[i];
}
if (antibold(words[i])==0) {
final_str = final_str + " <b>" + words[i] + "</b>";
}
else {
final_str = final_str + " <b>" + words[i].slice(0, bold_letters(words[i])) + "</b>" + words[i].slice(0-antibold(words[i]));
}
i++;
}
document.getElementById("Text").innerHTML = final_str;
</script>
1 Like
Nvm just had to look a bit harder. There is a different code for it.
For those interested to try it. I put this together from different sources. You can add it to your card template.
$(document).ready(function() {
const FIXATION_POINTS = [
[0, 4, 12, 17, 24, 29, 35, 42, 48],
[1, 2, 7, 10, 13, 14, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49],
[1, 2, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49],
[0, 2, 4, 5, 6, 8, 9, 11, 14, 15, 17, 18, 20, 0, 21, 23, 24, 26, 27, 29, 30, 32, 33, 35, 3…
1 Like
That’s a good code.
I think the first code would work if you enclose the text in <div id="Text">
<div id="Text"> text </div>
Hmm still doesnt seem to work. Do you mean putting the div tag inside or outside of the script
wait so i actually tested it and it turns out that it actually works with the simple input of just text
But it still doesn’t work for the entire cloze note. If I do put {{edit:cloze:Text}} instead of just Text, it just adds complete trash to within my text.
As you can see, the text looks a bit formatted but then code just suddenly pops up in the middle of nowhere.
I have the same problem :-/
The code by Ankiworld seems to work well with cloze, so I think that’s good enough.
Do you know how to make this code load faster and almost lag-free tho. Or is this something I am going to have to live with
How can I change this code I found on Reddit so that it works for the bionic reading of my cloze cards? I couldn’t get them to work with me on my own. The field name is just Text
The addon version painfully lags every time I load up the text, so I figured maybe if the code is embedded in the template it would load up faster.
@Shigeyuki ?
[image]
<script>
function bold_letters(word) {
var len = word.length;
if (!(/^[a-zA-Z]+$/.test(word))) {
…
Keks
March 30, 2024, 11:42am
9
brishtibheja:
What is Bionic Reading?
If you want to try it, then take a closer look at “Quickify” - for android
1 Like
sorata
March 30, 2024, 1:51pm
10
I don’t understand how it’s in-depth. It does help people hide mistakes in spelling (see through, third line)
Keks
March 30, 2024, 7:45pm
11
Perhaps this was not the best description. It rather helps to read a little faster.
1 Like
On my device there is no lag long enough to distract me with long sentences.
(Well, you might be distracted by it)
Maybe the card template is interfering, so you might want to test if you get the same lag with plain long text.
1 Like
You may already know this since you asked about the Font in another thread, using this Font for bionic-reading may reduce lag. (It was mentioned in a comment on the add-on page, and it works with cloze)
1 Like
Wow. I downloaded the ttf file, and it works like magic. Much faster as a downloadable font than having to apply code.
I found a code that runs faster. Here it is if your are interested
function bold_letters(word) {
var len = word.length;
if (!(/+$/.test(word))) {
return 0;
}
if (len < 1) {
return 0;
}
if (len <= 3) {
return 1;
}
if (len == 4) {
return 2;
} else {
return Math.round(len / 2);
}
}
var text = document.getElementById(“shank”).innerHTML;
var words = text.split(" ");
var final_str = “”;
for (var i = 0; i < words.length; i++) {
var bold_chars = bold_letters(words[i]);
if (bold_chars > 0) {
final_str += " " + words[i].substring(0, bold_chars) + “ ” + words[i].substring(bold_chars);
} else {
final_str += " " + words[i];
}
}
document.getElementById(“shank”).innerHTML = final_str;
But downloading the font works so much better! Thank you.
1 Like
Btw is there a font version which colours the bolded part of each word. That will be even much, much better
1 Like
I can’t find a font to color bold text, perhaps it would require creating a font or Javascript.
However, this add-on to color text is interesting, I repaired it and uploaded it to AnkiWeb.
It’s not a font, but it’s probably faster since it edits the HTML directly.
1 Like
Hmm doesnt seem to work. I find no edit in the HTML and my cloze field name is indeed Text. So what does the edit in HTML look like.
Here is the configuration in case it helps
Hmm…I still cant find an option.
It would be more practical I think if it applies it self automatically, but oh well…
And let me know if you find a version of this font where the bolded part is coloured pls Help with Bionic Reading Code - #13 by Shigeyuki
I think “beeline” has been added to the Browse menu bar.
1 Like