generated at
Scrapboxの行頭に✅を追加するショートカットは書けるか?
Scrapboxの行頭に✅を追加するショートカット用のUserScriptは書けるか?
難しそう。

その場所で、というなら以下でいける
script.js
(() => { const checkBoxList = ['⬜', '✅']; const textArea = document.getElementById('text-input'); const inputEvent = { event: document.createEvent('Event'), dispatch: function(string) { textArea.value = string; textArea.dispatchEvent(this.event); } }; inputEvent.event.initEvent('input', true, true); const onKeyDown = function(e){ if (e.altKey) { inputEvent.dispatch(checkBoxList[1]); } } document.addEventListener('keydown', onKeyDown) })()

document.execCommand を使えば、もっと簡単な気もする。

これでaltキーでチェックボックス(チェック済み)を追加できる。
キーイベントで分岐すれば、チェック済みでないボックスの追加もできいる。
たとえば、 switch (e.keyCode) { 的な?

以下を参考に書いた。

ショートカットキーの追加の参考
kpt.js
(() => { const aliases = { KeyK: 'keep', KeyP: 'problem', KeyT: 'try', } const onKeyDown = function(e){ if (e.altKey) { const cursor = document.getElementById('text-input') const name = aliases[e.code] if (name) { e.preventDefault() cursor.focus() document.execCommand('insertText', null, `[${name}.icon]`) } } } document.addEventListener('keydown', onKeyDown) })()

かーそるがある行の、先頭にこれを追加したい。

sample.js
const checkBoxList = ['⬜', '✅'];   const textArea = document.getElementById('text-input');      const inputEvent = { event: document.createEvent('Event'), dispatch: function(string) { textArea.value = string; textArea.dispatchEvent(this.event); } }; inputEvent.event.initEvent('input', true, true); $('#text-input').off('keydown.autoInsertCheckBox'); $('#text-input').on('keydown.autoInsertCheckBox', e => { switch (e.keyCode) { case 13: // Enter if (!startsWithBoxReg.test(getCursorLineString())) return; setTimeout(() => { if (startsWithBoxReg.test(getCursorLineString())) return; inputEvent.dispatch(checkBoxList[0]); }, 50); break; default: return; } }); function isFirstElementChild(elem) { return elem.parentNode.firstElementChild === elem; } function getCursorLineString() { return document.querySelector('.lines div.line.cursor-line').textContent; }