let input = iframeDoc.querySelector('pre.edit[contenteditable="true"]')
await sleep(300)
await simulateHumanInputAwait(input, "你好")
async function simulateHumanInput(target, value, interval = 80) {
target.focus()
target.innerText = ""
for (let i = 0; i < value.length; i++) {
const char = value[i]
target.innerText += char
// 生成输入事件
const inputEvent = new InputEvent("input", {
bubbles: true,
data: char,
inputType: "insertText"
})
target.dispatchEvent(inputEvent)
// 键盘事件
const keyEventDown = new KeyboardEvent("keydown", {
key: char,
bubbles: true
})
const keyEventUp = new KeyboardEvent("keyup", { key: char, bubbles: true })
target.dispatchEvent(keyEventDown)
target.dispatchEvent(keyEventUp)
await sleep(interval + Math.random() * 30)
}
target.blur()
}