scrapbox-insert-text-2
/icons/hr.icon
引数の形を単純にした
非同期関数化した
入力完了まで待つ (1ms)
待機時間は{wait}で調節できる
code:script.js
import {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);
}
テストコード
code:js
import('/api/code/takker/scrapbox-insert-text-2/test1.js');
code:test1.js
import {insertText} from './script.js';
import {scrapboxDOM} from '../scrapbox-dom-accessor/script.js';
window.insertText = insertText;
scrapboxDOM.textInput.addEventListener('change', e => console.log(e));