Skip to content

Instantly share code, notes, and snippets.

@40thieves
Last active August 11, 2022 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 40thieves/2104d9606a88c252c1d3f1227d66455a to your computer and use it in GitHub Desktop.
Save 40thieves/2104d9606a88c252c1d3f1227d66455a to your computer and use it in GitHub Desktop.
Script that can emulate continual typing in a CM6 editor, to aid performance testing
let editor = document.querySelector('.cm-content')
let timer = null
let char = 'a'
let orig = char
let copy = null
function run() {
if (copy == null || !copy.length) {
copy = orig.slice() + ' ' + new Date() + '\n'
}
char = copy[0]
copy = copy.slice(1)
editor.focus()
document.execCommand('insertText', false, char)
timer = setTimeout(run, 100 + (Math.random() < 0.1 ? 1000 : 0))
}
window._chaosMonkey = run
window._clearChaosMonkey = ()=>{
clearTimeout(timer)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment