選択した行にチェックボックスをつける機能を追加する
選択した行にタスク用のチェックボックスを順番に切り替えて追加できる。
code:example
あああ
↓
o あああ
↓
v あああ
↓
あああ
(以下ループ)
参考
/choiyaki/20250413日誌#67fb15f700000000007cf82e
元にした→/progfay-pub/Replace Text UserScript
併用→/scrasobox/チェックボックスになるタグ 2
🔰使い方
以下のコードを自分のCosenseページに貼り付ける
貼り付けた後は更新を忘れない(cmd+R)
読み込まれると、ポップアップメニューに「チェックボックス」ボタンが表示されるようになる
チェックボックス
code:script.js
(function () {
function cycleCheckboxState() {
const textarea = document.querySelector('textarea.text-input');
if (!textarea) {
alert('エディタが見つかりません');
return;
}
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
const selectedText = textarea.value.slice(start, end);
if (!selectedText) {
alert('テキストを選択してください');
return;
}
const lines = selectedText.split('\n');
const updatedLines = lines.map(line => {
const trimmed = line.trimStart();
if (trimmed.startsWith('o')) {
// o → v
return line.replace('o', 'v');
} else if (trimmed.startsWith('v')) {
// v → チェックを消す(中身だけ残す)
return line.replace('v', '').trimStart();
} else {
// チェックなし → o を追加
return [o] ${line};
}
});
const newText = updatedLines.join('\n');
const before = textarea.value.slice(0, start);
const after = textarea.value.slice(end);
textarea.value = before + newText + after;
const newCursor = before.length + newText.length;
textarea.setSelectionRange(newCursor, newCursor);
textarea.dispatchEvent(new Event('input', { bubbles: true }));
console.log('🔁 チェックボックス:4ステップループ完了');
}
// UIにボタン追加
if (typeof cosense !== 'undefined' && cosense.PopupMenu) {
cosense.PopupMenu.addButton({
title: 'チェックボックス',
onClick: cycleCheckboxState
});
} else {
const button = document.createElement('button');
button.textContent = 'チェックボックス4ステップ';
button.style.position = 'fixed';
button.style.top = '330px';
button.style.right = '10px';
button.style.zIndex = '9999';
button.onclick = cycleCheckboxState;
document.body.appendChild(button);
}
})();
チェックボックスを表示する
code:style.css
/* チェックボックスになるタグ v2 Font Awesome版 */
.line:not(.cursor-line) ahref$='/o':not(.icon) span,
.line:not(.cursor-line) ahref$='/v':not(.icon) span {
display: inline-block; width: 0; text-indent: -9999px }
.line:not(.cursor-line) ahref$='/o':not(.icon)::after,
.line:not(.cursor-line) ahref$='/v':not(.icon)::after {
display: inline-block; min-width: 1.15em; padding-left: 1px;
font-family: 'Font Awesome 5 Free'; font-weight: 400;
font-size: 120%; text-align: center; vertical-align: middle }
.line:not(.cursor-line) ahref$='/o':not(.icon)::after { content: '\f0c8'; color: #08BDBD }
.line:not(.cursor-line) ahref$='/v':not(.icon)::after { content: '\f14a'; color: #2489C5 }