タスクの状態アイコンを切り替えるUserScript
https://gyazo.com/3101268fa4e0ca77d4479ad3c0cfd8b5
機能
<C-Space>を押すと、現在行の先頭に/icons/TODO.iconを追記する
連打すると以下が順に切り換わる
/icons/TODO.icon
/icons/doing.icon
/icons/done.icon
(無し)
実装
2021-09-27 12:20:07 終了
実装したいこと
アイコンクリックでも切り替えられるようにする
smartphoneからも操作しやすくなる
code:script.js
import {press} from '../scrapbox-keyboard-emulation-2/script.js';
import {sleep} from '../sleep/script.js';
import {insertText} from '../scrapbox-insert-text-2/script.js';
import {position} from '../scrapbox-cursor-position-6/script.js';
import {goHeadWithoutBlank} from '../scrapbox-cursor-emulation/cursor.js';
let repeat = false;
const textInput = document.getElementById('text-input');
const todo = "/icons/TODO.icon";
const doing = "/icons/doing.icon";
const done = "/icons/done.icon";
document.addEventListener('keyup', e => {
if (document.activeElement !== textInput) return;
const {ctrlKey, key} = e;
if (key !== ' ' || !ctrlKey) return;
e.preventDefault();
e.stopPropagation();
repeat = false;
});
document.addEventListener('keydown', e => {
if (document.activeElement !== textInput) return;
const {ctrlKey, key} = e;
if (key !== ' ' || !ctrlKey) return;
e.preventDefault();
e.stopPropagation();
if (repeat) return;
goHeadWithoutBlank();
switch (icon) {
case todo:
icon.split("").forEach(() => press('Delete'));
insertText(doing);
break;
case doing:
icon.split("").forEach(() => press('Delete'));
insertText(done);
break;
case done:
icon.split("").forEach(() => press('Delete'));
break;
default:
insertText(todo);
break;
}
repeat = true;
});