scrapbox-insert-text-2
引数の形を単純にした
非同期関数化した
入力完了まで待つ (1ms)
待機時間は {wait}
で調節できる
script.jsimport {scrapboxDOM} from '../scrapbox-dom-accessor/script.js';
import {sleep} from '../sleep/script.js';
export async function insertText(text, {wait = 1} = {}) {
const cursor = scrapboxDOM.textInput;
cursor.focus();
cursor.value = text;
const uiEvent = document.createEvent('UIEvent');
uiEvent.initEvent('input', true, false);
cursor.dispatchEvent(uiEvent);
await sleep(wait);
}
テストコード
jsimport('/api/code/takker/scrapbox-insert-text-2/test1.js');
test1.jsimport {insertText} from './script.js';
import {scrapboxDOM} from '../scrapbox-dom-accessor/script.js';
window.insertText = insertText;
scrapboxDOM.textInput.addEventListener('change', e => console.log(e));