音声入力するUserScript
code:script.js
(() => {
if (!webkitSpeechRecognition) return
const isMobile = () => /mobile/i.test(navigator.userAgent)
const writeText = (text) => {
console.log('writeText', text);
const textarea = document.getElementById("text-input");
const reactKey = Object.keys(textarea).find((key) => key.startsWith("__reactFiber"));
textareareactKey.return.return.stateNode._stores.find((store) => store.constructor.name === "Cursor").focus(); document.execCommand('insertText', null, text);
}
const recognition = new webkitSpeechRecognition()
if (!isMobile()) recognition.continuous = true
recognition.onresult = (e) => {
writeText(item.transcript + '\n');
}
let enable = false
scrapbox.PageMenu.addMenu({
title: 'speech input',
onClick: () => {
recognition.start();
// stopはブラウザからやる
//if (!isMobile()) enable = !enable;
}
});
})();
参考