Last active
August 11, 2022 14:44
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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