Files
devbox/js/cat-board.js
T
gitea 1fd857433d 第三批工具:画板/看板/打卡/字幕/语音/音频测试(270 → 313)
- cat-board.js: 待办、便利贴、看板、习惯打卡、心情记录、SWOT、甘特、组织架构、
  值班表、签到表、课程表、行李清单、人生日历、闪卡、方格纸(localStorage 持久化)
- cat-misc.js: 白板、签名板、代码转图、LED 字幕、提词器、速读、语音合成/识别、
  听力/声道测试、白噪音、节拍器、触摸/PPI/GPU/字体预览、字幕位移与 SRT⇄VTT、
  .ics 日历、礼物交换、敏感词、邮箱/链接/号码提取、slug、花体字、小红书排版
2026-11-20 14:58:29 +08:00

276 lines
19 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* DevBox · 画板 / 清单 / 表格类(数据存本地 localStorage) */
(function () {
'use strict'
const { el, panelTitle, toast, download, downloadText } = DB
const btn = (l, f, c = '') => el('button', { class: 'btn ' + c, text: l, onclick: f })
const pane = (t, r) => { const p = el('div', { class: 'panel' }); if (t) p.append(panelTitle(t, r)); return p }
const KEY = (id) => 'devbox.' + id
const load = (id, def) => { try { return JSON.parse(localStorage.getItem(KEY(id))) ?? def } catch (e) { return def } }
const save = (id, v) => localStorage.setItem(KEY(id), JSON.stringify(v))
/* 待办 */
DB.tool({
id: 'todo-list', name: '待办清单', group: 'office', icon: 'check', desc: '勾选式待办,存在本地浏览器,刷新不丢', keywords: ['todo', '待办', '清单'],
mount(root) {
const items = load('todo', [])
const list = el('div', { class: 'result-list' })
const input = el('input', { type: 'text', placeholder: '要做的事,回车添加', class: 'input' })
const paint = () => { list.textContent = ''
items.forEach((it, i) => {
const row = el('div', { class: 'row between extract-row' },
el('label', { class: 'row', style: { gap: '8px' } }, el('input', { type: 'checkbox', checked: it.done, onchange: () => { it.done = !it.done; save('todo', items); paint() } }), el('span', { text: it.text, style: { textDecoration: it.done ? 'line-through' : 'none', opacity: it.done ? .55 : 1 } })),
btn('删', () => { items.splice(i, 1); save('todo', items); paint() }, 'ghost'))
list.append(row) })
if (!items.length) list.append(el('div', { class: 'hint', text: '还没有待办' })) }
input.addEventListener('keydown', (e) => { if (e.key === 'Enter' && input.value.trim()) { items.push({ text: input.value.trim(), done: false }); input.value = ''; save('todo', items); paint() } })
root.append(pane('待办', btn('清空已完成', () => { for (let i = items.length - 1; i >= 0; i--) if (items[i].done) items.splice(i, 1); save('todo', items); paint() }, 'ghost')), input, list)
paint()
},
})
/* 便利贴 */
DB.tool({
id: 'sticky-notes', name: '便利贴', group: 'office', icon: 'text', desc: '一页随手记,自动保存,当草稿纸用', keywords: ['便签', '笔记', 'sticky'],
mount(root) {
const note = load('note', '')
const ta = el('textarea', { class: 'ta', rows: 16, placeholder: '随手记点什么…(自动保存)' })
ta.value = note
let t = 0
ta.addEventListener('input', () => { clearTimeout(t); t = setTimeout(() => { save('note', ta.value); DB.toast('已保存') }, 600) })
root.append(pane('便利贴', el('div', { class: 'row' }, btn('导出 .txt', () => downloadText('note.txt', ta.value), 'ghost'), btn('清空', () => { ta.value = ''; save('note', ''); }, 'ghost'))), ta)
},
})
/* 看板 */
DB.tool({
id: 'kanban-board', name: '看板', group: 'office', icon: 'box', desc: '待办 / 进行中 / 已完成 三栏,点卡片换栏', keywords: ['kanban', '看板', '任务'],
mount(root) {
const cols = load('kanban', { todo: [], doing: [], done: [] })
const paint = () => { wrap.textContent = ''
for (const [key, label] of [['todo', '待办'], ['doing', '进行中'], ['done', '已完成']]) {
const col = el('div', { class: 'panel', style: { minWidth: '150px' } })
col.append(el('div', { class: 'row between' }, el('b', { text: `${label} (${cols[key].length})` }),
btn('+', () => { const v = prompt('内容'); if (v) { cols[key].push(v); save('kanban', cols); paint() } }, 'ghost')))
cols[key].forEach((c, i) => { const card = el('div', { class: 'card', style: { padding: '8px 10px', marginTop: '6px', cursor: 'pointer' }, text: c })
card.title = '点击移到下一栏'
card.addEventListener('click', () => { const order = ['todo', 'doing', 'done']; const next = order[(order.indexOf(key) + 1) % 3]
cols[key].splice(i, 1); cols[next].push(c); save('kanban', cols); paint() })
col.append(card) })
wrap.append(col) } }
const wrap = el('div', { class: 'row', style: { gap: '10px', alignItems: 'flex-start', flexWrap: 'wrap' } })
root.append(pane('看板', btn('清空', () => { cols.todo = []; cols.doing = []; cols.done = []; save('kanban', cols); paint() }, 'ghost')), wrap)
paint()
},
})
/* 习惯打卡 */
DB.tool({
id: 'habit-tracker', name: '习惯打卡', group: 'office', icon: 'check', desc: '最近 7 天打卡格子,点一下标记完成', keywords: ['习惯', '打卡', 'habit'],
mount(root) {
const data = load('habit', { habit: '喝水', days: {} })
const nameInput = el('input', { type: 'text', class: 'input', value: data.habit })
nameInput.addEventListener('change', () => { data.habit = nameInput.value; save('habit', data) })
const grid = el('div', { class: 'row', style: { gap: '6px', flexWrap: 'wrap' } })
const paint = () => { grid.textContent = ''
for (let i = 6; i >= 0; i--) { const d = new Date(Date.now() - i * 86400000); const k = d.toISOString().slice(0, 10)
const on = data.days[k]
const cell = el('button', { class: 'find-chip' + (on ? ' on' : ''), text: `${d.getMonth() + 1}/${d.getDate()}`, onclick: () => { data.days[k] = !on; save('habit', data); paint() } })
grid.append(cell) }
const n = Object.values(data.days).filter(Boolean).length
stat.textContent = `共打卡 ${n} 天` }
const stat = el('div', { class: 'hint' })
root.append(pane('习惯打卡'), el('div', { class: 'row' }, el('span', { text: '习惯:' }), nameInput), grid, stat)
paint()
},
})
/* 心情记录 */
DB.tool({
id: 'mood-tracker', name: '心情记录', group: 'life', icon: 'bolt', desc: '每天一句心情 + 打分,看最近状态', keywords: ['心情', 'mood', '情绪'],
mount(root) {
const list = load('mood', [])
const face = el('select', { class: 'input' }, ...[['😄 很好', 5], ['🙂 还行', 4], ['😐 一般', 3], ['😕 有点烦', 2], ['😩 很糟', 1]].map(([t, v]) => el('option', { value: v, text: t })))
const note = el('input', { class: 'input', type: 'text', placeholder: '一句话(可选)' })
const out = el('div', { class: 'result-list' })
const paint = () => { out.textContent = ''
list.slice(-14).reverse().forEach((m) => out.append(el('div', { class: 'row between' }, el('span', { text: `${m.date} ${'●'.repeat(m.score)}${'○'.repeat(5 - m.score)}` }), el('span', { class: 'hint', text: m.note || '' }))))
const avg = list.length ? (list.reduce((a, b) => a + b.score, 0) / list.length).toFixed(1) : '-'
stat.textContent = `共 ${list.length} 条记录,平均 ${avg} 分` }
const stat = el('div', { class: 'hint' })
root.append(pane('心情', btn('记一笔', () => { list.push({ date: new Date().toISOString().slice(0, 10), score: +face.value, note: note.value }); save('mood', list); note.value = ''; paint() })),
el('div', { class: 'row' }, face, note), stat, out)
paint()
},
})
/* SWOT */
DB.tool({
id: 'swot-canvas', name: 'SWOT 分析', group: 'office', icon: 'box', desc: '优势/劣势/机会/威胁 四象限,自动保存', keywords: ['swot', '分析', '战略'],
mount(root) {
const d = load('swot', { s: '', w: '', o: '', t: '' })
const mk = (k, label, color) => { const ta = el('textarea', { class: 'ta', rows: 5, placeholder: label })
ta.value = d[k]; ta.addEventListener('input', () => { d[k] = ta.value; save('swot', d) })
return el('div', { class: 'panel', style: { borderTop: '2px solid ' + color } }, el('b', { text: label }), ta) }
root.append(pane('SWOT'), el('div', { class: 'grid2' },
mk('s', 'S 优势', '#33d6a6'), mk('w', 'W 劣势', '#ff8a8a'), mk('o', 'O 机会', '#5b8cff'), mk('t', 'T 威胁', '#f0b34f')))
},
})
/* 甘特图 */
DB.tool({
id: 'gantt-chart', name: '甘特图(文本)', group: 'office', icon: 'calendar', desc: '「任务|开始|结束」三列,生成 ASCII 甘特图', keywords: ['gantt', '甘特', '排期'],
mount(root) {
const ta = el('textarea', { class: 'ta', rows: 6, placeholder: '设计|2026-11-01|2026-11-08\n开发|2026-11-07|2026-11-25' })
const out = el('pre', { class: 'out' })
const run = () => { try {
const rows = ta.value.split(/\n/).map((l) => l.split('|').map((x) => x.trim())).filter((r) => r.length >= 3 && r[1] && r[2])
if (!rows.length) { out.textContent = '按「任务|开始|结束」填一行'; return }
const days = rows.map(([, a, b]) => [new Date(a), new Date(b)])
const min = Math.min(...days.map(([a]) => a)), max = Math.max(...days.map(([, b]) => b))
const total = Math.max(1, Math.round((max - min) / 86400000) + 1)
const cell = total > 60 ? 1 : Math.ceil(60 / total)
out.textContent = rows.map((r, i) => { const [a, b] = days[i]
const start = Math.round((a - min) / 86400000), len = Math.max(1, Math.round((b - a) / 86400000))
const left = Math.round(start / total * 40), bar = Math.max(1, Math.round(len / total * 40))
return `${r[0].padEnd(10, ' ')} ${' '.repeat(left)}${'█'.repeat(bar)} ${r[1]}→${r[2]}` }).join('\n') + `\n\n跨期 ${total} 天(${min.toLocaleDateString('zh-CN')} — ${max.toLocaleDateString('zh-CN')})`
} catch (e) { out.textContent = '日期格式不对:' + e.message } }
ta.addEventListener('input', run)
root.append(pane('甘特图'), ta, out)
run()
},
})
/* 组织架构 */
DB.tool({
id: 'org-chart', name: '组织架构(缩进树)', group: 'office', icon: 'box', desc: '用缩进写层级,生成树状图', keywords: ['org', '组织架构', '树'],
mount(root) {
const ta = el('textarea', { class: 'ta', rows: 8, placeholder: 'CEO\n 技术\n 前端\n 后端\n 市场' })
const out = el('pre', { class: 'out' })
const run = () => { const rows = ta.value.split(/\n/).filter((l) => l.trim()); if (!rows.length) { out.textContent = '用两个空格表示下级'; return }
const base = Math.min(...rows.map((l) => l.search(/\S/)))
out.textContent = rows.map((l, i) => { const ind = Math.max(0, Math.floor((l.search(/\S/) - base) / 2)); const last = i === rows.length - 1 || (rows[i + 1] && Math.floor((rows[i + 1].search(/\S/) - base) / 2) < ind)
return ' '.repeat(ind) + (ind ? (last ? '└─ ' : '├─ ') : '') + l.trim() }).join('\n') }
ta.addEventListener('input', run)
root.append(pane('组织架构'), ta, out); run()
},
})
/* 值班表 */
DB.tool({
id: 'duty-roster', name: '值班表', group: 'office', icon: 'calendar', desc: '按名单轮班,生成一个月排班表', keywords: ['值班', '排班', 'roster'],
mount(root) {
const names = el('input', { class: 'input', type: 'text', value: '张三,李四,王五,赵六' })
const days = el('input', { class: 'input', type: 'number', value: 30, min: 1, max: 90 })
const out = el('pre', { class: 'out' })
const run = () => { const l = names.value.split(/[,,\s]+/).filter(Boolean); if (!l.length) return
const n = +days.value || 30; const start = new Date(); const rows = []
for (let i = 0; i < n; i++) { const d = new Date(start.getTime() + i * 86400000); rows.push(`${d.toLocaleDateString('zh-CN')} ${l[i % l.length]}`) }
out.textContent = rows.join('\n') }
names.addEventListener('input', run); days.addEventListener('input', run)
root.append(pane('值班表', btn('导出 CSV', () => downloadText('duty.csv', out.textContent.replace(/ +/g, ',')))), el('div', { class: 'row' }, names, days), out); run()
},
})
/* 点名表 / 打卡表 */
DB.tool({
id: 'attendance-sheet', name: '考勤表', group: 'office', icon: 'box', desc: '名单 × 天数生成带勾选框的表格文本', keywords: ['考勤', '签到', '表'],
mount(root) {
const names = el('input', { class: 'input', type: 'text', value: '张三,李四,王五' })
const days = el('input', { class: 'input', type: 'number', value: 10, min: 1, max: 31 })
const out = el('pre', { class: 'out' })
const run = () => { const l = names.value.split(/[,,]/).map((x) => x.trim()).filter(Boolean); const n = +days.value || 10
const head = ['姓名', ...Array.from({ length: n }, (_, i) => String(i + 1))].join('\t')
out.textContent = head + '\n' + l.map((x) => [x, ...Array.from({ length: n }, () => '□')].join('\t')).join('\n') }
names.addEventListener('input', run); days.addEventListener('input', run)
root.append(pane('考勤表'), el('div', { class: 'row' }, names, days), out); run()
},
})
/* 课程表 */
DB.tool({
id: 'class-timetable', name: '课程表', group: 'office', icon: 'calendar', desc: '一周五天 × 节次,生成可粘贴的课程表', keywords: ['课程表', '课表', 'class'],
mount(root) {
const ta = el('textarea', { class: 'ta', rows: 7, placeholder: '周一: 语文,数学,英语\n周二: 数学,物理' })
const out = el('pre', { class: 'out' })
const run = () => { const rows = ta.value.split(/\n/).map((l) => l.split(/[::]/)).filter((r) => r.length >= 2)
const data = rows.map(([d, c]) => [d.trim(), c.split(/[,,]/).map((x) => x.trim())])
const maxn = Math.max(0, ...data.map(([, c]) => c.length))
const head = ['节次', ...data.map(([d]) => d)]
const lines = [head.join('\t')]
for (let i = 0; i < maxn; i++) lines.push([`第${i + 1}节`, ...data.map(([, c]) => c[i] || '')].join('\t'))
out.textContent = lines.join('\n') }
ta.addEventListener('input', run)
root.append(pane('课程表'), ta, out); run()
},
})
/* 打包清单 */
DB.tool({
id: 'packing-list', name: '行李清单', group: 'life', icon: 'check', desc: '按出行类型给一份打包清单,可勾选', keywords: ['打包', '行李', '旅行'],
mount(root) {
const kind = el('select', { class: 'input' }, el('option', { value: '出差', text: '出差 2–3 天' }), el('option', { value: '旅行', text: '旅行 5 天+' }), el('option', { value: '露营', text: '露营' }))
const list = el('div', { class: 'result-list' })
const MAP = {
出差: ['身份证/护照', '笔记本 + 充电器', '手机充电器 + 充电宝', '换洗衣物 ×2', '洗漱包', '名片/工牌', '常备药', '耳机', '伞'],
旅行: ['证件与复印件', '衣物按天算 +1 套', '洗漱用品', '防晒与帽子', '转换插头', '常用药与创可贴', '充电宝(≤100Wh)', '相机/存储卡', '现金零钱'],
露营: ['帐篷与地钉', '睡袋/防潮垫', '头灯 + 备用电池', '炉具与燃料', '保暖层', '雨具', '垃圾袋', '驱蚊', '急救包'],
}
const paint = () => { list.textContent = ''
for (const it of MAP[kind.value]) list.append(el('label', { class: 'row', style: { gap: '8px', padding: '4px 0' } }, el('input', { type: 'checkbox' }), el('span', { text: it }))) }
kind.addEventListener('change', paint)
root.append(pane('行李清单'), kind, list); paint()
},
})
/* 人生日历 */
DB.tool({
id: 'life-calendar', name: '人生格子', group: 'life', icon: 'calendar', desc: '一年 52 周画成格子,看到时间去哪了', keywords: ['人生', '日历', '格子'],
mount(root) {
const y = el('input', { class: 'input', type: 'number', value: new Date().getFullYear(), min: 1900, max: 2100 })
const out = el('pre', { class: 'out' })
const run = () => { const year = +y.value || new Date().getFullYear(); const now = new Date()
const rows = []
for (let m = 0; m < 12; m++) { const line = Array.from({ length: 31 }, (_, d) => { const dd = new Date(year, m, d + 1)
if (dd.getMonth() !== m) return ' '
return dd <= now ? '▣' : '▢' }).join('')
rows.push(`${String(m + 1).padStart(2, '0')} ${line}`) }
out.textContent = `${year} 年(▣ 已过 / ▢ 未到)\n` + rows.join('\n') }
y.addEventListener('input', run)
root.append(pane('人生格子'), y, out); run()
},
})
/* 闪卡 */
DB.tool({
id: 'flashcards', name: '闪卡背诵', group: 'life', icon: 'box', desc: '正面|背面 一行一个,点一下翻面,随机抽', keywords: ['闪卡', '背单词', 'flashcard'],
mount(root) {
const ta = el('textarea', { class: 'ta', rows: 6, placeholder: 'hello|你好\nabandon|放弃' })
const card = el('div', { class: 'clickpad', text: '点开始' })
const hint = el('div', { class: 'hint', text: '' })
let cards = [], i = -1, showBack = false
const load2 = () => ta.value.split(/\n/).map((l) => l.split('|')).filter((r) => r.length >= 2).map(([a, b]) => [a.trim(), b.trim()])
const next = () => { cards = load2(); if (!cards.length) { hint.textContent = '先按「正面|背面」填几行'; return }
i = (i + 1) % cards.length; showBack = false; card.textContent = cards[i][0]; hint.textContent = `第 ${i + 1} / ${cards.length} 张,点卡片翻面` }
card.addEventListener('click', () => { if (!cards.length) { next(); return } showBack = !showBack; card.textContent = showBack ? cards[i][1] : cards[i][0] })
root.append(pane('闪卡', el('div', { class: 'row' }, btn('开始/下一张', next), btn('打乱', () => { cards = load2().sort(() => Math.random() - .5); i = -1; next() }, 'ghost'))), ta, card, hint)
},
})
/* 方格纸 */
DB.tool({
id: 'graph-paper', name: '可打印方格纸', group: 'office', icon: 'box', desc: '生成 A4 方格 / 横线 / 点阵图,直接下载 PNG', keywords: ['方格纸', '打印', 'grid', '点阵'],
mount(root) {
const kind = el('select', { class: 'input' }, el('option', { value: 'grid', text: '方格' }), el('option', { value: 'line', text: '横线' }), el('option', { value: 'dot', text: '点阵' }))
const gap = el('input', { class: 'input', type: 'number', value: 40, min: 10, max: 120 })
const gen = () => { const W = 1240, H = 1754; const c = document.createElement('canvas'); c.width = W; c.height = H
const g = c.getContext('2d'); g.fillStyle = '#fff'; g.fillRect(0, 0, W, H); g.strokeStyle = '#c9d3e0'; g.fillStyle = '#c9d3e0'; g.lineWidth = 1
const k = gap.value | 0
if (kind.value === 'grid') { for (let x = k; x < W; x += k) { g.beginPath(); g.moveTo(x, 0); g.lineTo(x, H); g.stroke() } for (let y = k; y < H; y += k) { g.beginPath(); g.moveTo(0, y); g.lineTo(W, y); g.stroke() } }
else if (kind.value === 'line') { for (let y = k; y < H; y += k) { g.beginPath(); g.moveTo(0, y); g.lineTo(W, y); g.stroke() } }
else { for (let x = k; x < W; x += k) for (let y = k; y < H; y += k) { g.beginPath(); g.arc(x, y, 1.4, 0, 7); g.fill() } }
download(`paper-${kind.value}.png`, c.toDataURL('image/png')) }
root.append(pane('方格纸', el('div', { class: 'row' }, kind, gap, btn('生成 A4 PNG', gen))))
},
})
})()