Thank you for this script! If anyone is interested, I improved it a little in terms of events (compositionstart wasn’t working for example):
$(‘body’).on(’.typing input’, ‘input’, function() {
processInput();
});$('body').on('select', function() { processInput(); }); function processInput () { var b = MEMRISE.garden.box, p = b.testData.correct, i = b.$input.input || b.$input, v = i.val(), sliceIndex = 0; for (let a of p) { if (a.indexOf(v) !== 0) { var aNoDiacritics = getNonDiacritics(a).toLowerCase(); var aSimple = getNonPunctuation(aNoDiacritics); var vSimple = getNonPunctuation(getNonDiacritics(v)).toLowerCase(); if (aSimple.indexOf(vSimple) === 0) { var noDiacriticSliceIndex = aNoDiacritics.match(new RegExp(`.*?${vSimple.split("").join(".*?")}((${punctuation.source}|\\s)+$){0,1}`))[0].length; var counter = 0; for (let i = 0; i < a.length; i++) { counter += getNonDiacritics(a[i]).length; if(counter <= noDiacriticSliceIndex) sliceIndex++; else break; } } } else { try{ sliceIndex = a.match(new RegExp(`${v}((${punctuation.source}|\\s)+$){0,1}`))[0].length; }catch(e){ console.log(e); //break; } } if (sliceIndex) { var replacement = a.slice(0, sliceIndex); i.val(replacement); if(v !== replacement) { console.log(v); console.log(replacement); $('.typing-type-here').trigger('keydown'); } break; } } }