From 1fd857433d0e5acc89236d4541d1b8b9b2b1f937 Mon Sep 17 00:00:00 2001 From: gitea Date: Fri, 20 Nov 2026 14:58:29 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=89=B9=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=EF=BC=9A=E7=94=BB=E6=9D=BF/=E7=9C=8B=E6=9D=BF/=E6=89=93?= =?UTF-8?q?=E5=8D=A1/=E5=AD=97=E5=B9=95/=E8=AF=AD=E9=9F=B3/=E9=9F=B3?= =?UTF-8?q?=E9=A2=91=E6=B5=8B=E8=AF=95=EF=BC=88270=20=E2=86=92=20313?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - cat-board.js: 待办、便利贴、看板、习惯打卡、心情记录、SWOT、甘特、组织架构、 值班表、签到表、课程表、行李清单、人生日历、闪卡、方格纸(localStorage 持久化) - cat-misc.js: 白板、签名板、代码转图、LED 字幕、提词器、速读、语音合成/识别、 听力/声道测试、白噪音、节拍器、触摸/PPI/GPU/字体预览、字幕位移与 SRT⇄VTT、 .ics 日历、礼物交换、敏感词、邮箱/链接/号码提取、slug、花体字、小红书排版 --- README.md | 3 +- index.html | 2 + js/cat-board.js | 275 ++++++++++++++++++++++++++++++++++++++++ js/cat-misc.js | 324 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 603 insertions(+), 1 deletion(-) create mode 100644 js/cat-board.js create mode 100644 js/cat-misc.js diff --git a/README.md b/README.md index 171129b..40c39ea 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # DevBox · 开发者工具箱 -一个开发者工具箱:200+ 个工具(图片转格式与加水印、哈希与 AES、JWT、时间戳、Cron、JSON、正则、Diff、颜色、CIDR、chmod、cURL 转代码……),外加**账号系统、积分计费和 CDK 兑换**,还有一个管理员后台。 +一个开发者工具箱:300+ 个工具(图片转格式与加水印、哈希与 AES、JWT、时间戳、Cron、JSON、正则、Diff、颜色、CIDR、chmod、cURL 转代码……),外加**账号系统、积分计费和 CDK 兑换**,还有一个管理员后台。 工具本身仍然在浏览器里算完,数据不出本机;只有「谁在用、还剩多少积分」记到服务端的 SQLite 里。零第三方依赖,一个 `node server.mjs` 就跑起来。 @@ -238,6 +238,7 @@ DB.tool({ ## 更新日志 +- 2026-11-20 第三批:工具数 270 → 313,补「画板/白板/看板/打卡/甘特/组织图、字幕位移与格式转换、语音合成与识别、音频测试与白噪音、白板与签名导出、代码转图片、提词器/速读、.ics 日历、邮箱/链接/号码提取」等 - 2026-11-20 首页加了「找工具」条:搜索框 + 分类小按钮(带数量),点分类立刻过滤 - 2026-11-20 参照 deertools.cn 大扩一轮:工具数 44 → 201,新增「随机 / 检测 / 办公 / 生活」分组 - 文本 45 个:大小写与命名、排序、去重、拆分合并、字数统计、词频、敏感信息打码、镜像/倒立/上标、Kaomoji、假数据 等 diff --git a/index.html b/index.html index 688d778..ea54889 100644 --- a/index.html +++ b/index.html @@ -169,6 +169,8 @@ + + diff --git a/js/cat-board.js b/js/cat-board.js new file mode 100644 index 0000000..5494da1 --- /dev/null +++ b/js/cat-board.js @@ -0,0 +1,275 @@ +/* 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)))) + }, + }) +})() diff --git a/js/cat-misc.js b/js/cat-misc.js new file mode 100644 index 0000000..b198f80 --- /dev/null +++ b/js/cat-misc.js @@ -0,0 +1,324 @@ +/* DevBox · 画布 / 声音 / 设备 / 小工具 */ +(function () { + 'use strict' + const { el, panelTitle, toast, download, downloadText, textTool: T, genTool: G } = 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 canvasOf = (w, h, cls) => { const c = el('canvas', { class: cls || 'drawpad', width: w, height: h }); c.style.width = '100%'; c.style.background = '#fff'; c.style.borderRadius = '10px'; c.style.border = '1px solid var(--line)'; return c } + + /* 白板 */ + DB.tool({ + id: 'whiteboard', name: '白板涂鸦', group: 'creator', icon: 'palette', desc: '手绘、调粗细颜色,能导出 PNG', keywords: ['白板', '涂鸦', '画板'], + mount(root) { + const c = canvasOf(1200, 700); const g = c.getContext('2d') + if (!g) { root.append(el('p', { class: 'hint', text: '当前环境不支持 canvas,请在浏览器中使用' })); return } + g.lineCap = 'round'; g.lineJoin = 'round' + const color = el('input', { type: 'color', value: '#1f2430' }) + const width = el('input', { type: 'range', min: 1, max: 24, value: 4 }) + let drawing = false + const pos = (e) => { const r = c.getBoundingClientRect(); const t = e.touches ? e.touches[0] : e; return [(t.clientX - r.left) * c.width / r.width, (t.clientY - r.top) * c.height / r.height] } + const start = (e) => { e.preventDefault(); drawing = true; g.strokeStyle = color.value; g.lineWidth = +width.value; g.beginPath(); g.moveTo(...pos(e)) } + const move = (e) => { if (!drawing) return; e.preventDefault(); g.lineTo(...pos(e)); g.stroke() } + const end = () => { drawing = false } + c.addEventListener('mousedown', start); c.addEventListener('mousemove', move); window.addEventListener('mouseup', end) + c.addEventListener('touchstart', start, { passive: false }); c.addEventListener('touchmove', move, { passive: false }); c.addEventListener('touchend', end) + root.append(pane('白板', el('div', { class: 'row' }, color, width, btn('清空', () => g.clearRect(0, 0, c.width, c.height), 'ghost'), btn('导出 PNG', () => download('whiteboard.png', c.toDataURL('image/png')), 'ghost'))), c) + }, + }) + + /* 手写签名 */ + DB.tool({ + id: 'signature-pad', name: '手写签名', group: 'creator', icon: 'code', desc: '鼠标或手指签个名,抠成透明 PNG 下载', keywords: ['签名', 'signature', '手写'], + mount(root) { + const c = canvasOf(1000, 360); const g = c.getContext('2d') + if (!g) { root.append(el('p', { class: 'hint', text: '当前环境不支持 canvas,请在浏览器中使用' })); return } + g.lineCap = 'round'; g.lineWidth = 3.2; g.strokeStyle = '#111' + const w = el('input', { type: 'range', min: 1, max: 12, value: 3, step: .5 }); w.addEventListener('input', () => { g.lineWidth = +w.value }) + let on = false + const pos = (e) => { const r = c.getBoundingClientRect(); const t = e.touches ? e.touches[0] : e; return [(t.clientX - r.left) * c.width / r.width, (t.clientY - r.top) * c.height / r.height] } + const st = (e) => { e.preventDefault(); on = true; g.beginPath(); g.moveTo(...pos(e)) } + const mv = (e) => { if (!on) return; e.preventDefault(); g.lineTo(...pos(e)); g.stroke() } + c.addEventListener('mousedown', st); c.addEventListener('mousemove', mv); window.addEventListener('mouseup', () => (on = false)) + c.addEventListener('touchstart', st, { passive: false }); c.addEventListener('touchmove', mv, { passive: false }); c.addEventListener('touchend', () => (on = false)) + root.append(pane('手写签名', el('div', { class: 'row' }, el('span', { text: '笔画' }), w, btn('清空', () => g.clearRect(0, 0, c.width, c.height), 'ghost'), btn('下载 PNG', () => download('signature.png', c.toDataURL('image/png')), 'ghost'))), c) + }, + }) + + /* 代码转图片 */ + DB.tool({ + id: 'code-to-image', name: '代码转图片', group: 'creator', icon: 'code', desc: '把一段代码渲染成深色卡片图,发群分享方便', keywords: ['代码图', 'code image', '分享'], + mount(root) { + const ta = el('textarea', { class: 'ta', rows: 10, placeholder: '// 粘代码 / 文本进来' }) + ta.value = 'function hello(name) {\n return `你好,${name}`\n}' + const title = el('input', { class: 'input', type: 'text', value: 'devbox.js' }) + const gen = () => { const lines = ta.value.split(/\n/); const fs = 22, lh = 34, pad = 34 + const c = document.createElement('canvas'); c.width = Math.min(1800, Math.max(520, Math.max(...lines.map((l) => l.length)) * fs * 0.62 + pad * 2)); c.height = lines.length * lh + pad * 2 + 46 + const g = c.getContext('2d') + if (!g) { root.append(el('p', { class: 'hint', text: '当前环境不支持 canvas,请在浏览器中使用' })); return } + g.fillStyle = '#151a23'; g.fillRect(0, 0, c.width, c.height) + g.fillStyle = '#2a3240'; g.fillRect(0, 0, c.width, 40); g.fillStyle = '#8b98ab'; g.font = '16px monospace'; g.fillText(title.value, 16, 26) + g.font = `${fs}px ui-monospace, Menlo, monospace`; g.fillStyle = '#e6edf3' + lines.forEach((l, i) => g.fillText(l, pad, pad + 46 + i * lh)) + download('code.png', c.toDataURL('image/png')) } + root.append(pane('代码转图片', el('div', { class: 'row' }, title, btn('生成 PNG', gen))), ta) + }, + }) + + /* LED 滚动字幕 */ + DB.tool({ + id: 'led-banner', name: 'LED 滚动字幕', group: 'creator', icon: 'bolt', desc: '全屏滚动文字,接机牌、年会抽奖公告都能用', keywords: ['led', '滚动', '字幕', '接机'], + mount(root) { + const text = el('input', { class: 'input', type: 'text', value: '欢迎来到 DevBox' }) + const speed = el('input', { type: 'range', min: 1, max: 12, value: 4 }) + const stage = el('div', { class: 'fullscreen-stage', style: { display: 'none', background: '#000' } }) + const line = el('div', { style: { position: 'absolute', top: '50%', transform: 'translateY(-50%)', whiteSpace: 'nowrap', color: '#ff3b3b', fontSize: '9vh', fontWeight: '700', textShadow: '0 0 18px rgba(255,59,59,.6)' } }) + stage.append(line); let raf = 0, x = 0, run = false + const loop = () => { if (!run) return; x -= +speed.value; if (x < -line.offsetWidth) x = stage.clientWidth; line.style.left = x + 'px'; raf = requestAnimationFrame(loop) } + const start = () => { line.textContent = text.value || ' '; stage.style.display = 'block'; x = stage.clientWidth; run = true; cancelAnimationFrame(raf); loop() } + const stop = () => { run = false; cancelAnimationFrame(raf); stage.style.display = 'none' } + stage.addEventListener('click', stop) + root.append(pane('LED 字幕', el('div', { class: 'row' }, text, speed, btn('全屏播放', start), btn('停止', stop, 'ghost'))), stage) + }, + }) + + /* 提词器 */ + DB.tool({ + id: 'teleprompter', name: '提词器', group: 'creator', icon: 'text', desc: '大字自动滚动,录视频念稿不用背', keywords: ['提词', 'teleprompter', '录视频'], + mount(root) { + const ta = el('textarea', { class: 'ta', rows: 8, placeholder: '把稿子粘进来' }) + const box = el('div', { style: { height: '320px', overflow: 'hidden', position: 'relative', background: '#0d1117', borderRadius: '12px', marginTop: '10px' } }) + const inner = el('div', { style: { padding: '40px 20px', color: '#e6edf3', fontSize: '30px', lineHeight: '1.6', whiteSpace: 'pre-wrap' } }) + box.append(inner) + let run = false, raf = 0, y = 0, speed = 1.2 + const loop = () => { if (!run) return; y += speed; inner.style.transform = `translateY(${-y}px)`; if (y > inner.scrollHeight) { run = false } raf = requestAnimationFrame(loop) } + const sl = el('input', { type: 'range', min: 0.3, max: 5, step: 0.1, value: 1.2 }); sl.addEventListener('input', () => { speed = +sl.value }) + root.append(pane('提词器', el('div', { class: 'row' }, sl, btn('开始', () => { inner.textContent = ta.value || '(先粘稿子)'; y = 0; run = true; loop() }), btn('暂停', () => { run = false; cancelAnimationFrame(raf) }, 'ghost'), btn('从头', () => { y = 0; inner.style.transform = 'translateY(0)' }, 'ghost'))), ta, box) + }, + }) + + /* 速读训练 */ + DB.tool({ + id: 'speed-reading', name: '速读训练', group: 'life', icon: 'bolt', desc: '逐词闪现,练眼睛不回头(RSVP)', keywords: ['速读', '阅读', 'rsvp'], + mount(root) { + const ta = el('textarea', { class: 'ta', rows: 6, placeholder: '粘一段文字,按词闪现' }) + const face = el('div', { class: 'big-time', text: '准备' }) + const wpm = el('input', { type: 'range', min: 100, max: 900, value: 300 }) + let iv = 0 + const start = () => { const words = (ta.value.match(/[\u4e00-\u9fa5]|[A-Za-z]+|[,。!?]/g) || []) + if (!words.length) { face.textContent = '先粘文字'; return } + let i = 0; clearInterval(iv); face.textContent = words[0] + iv = setInterval(() => { i++; if (i >= words.length) { clearInterval(iv); face.textContent = '读完'; return } face.textContent = words[i] }, 60000 / +wpm.value) } + root.append(pane('速读', el('div', { class: 'row' }, el('span', { text: '速度' }), wpm, btn('开始', start), btn('停', () => clearInterval(iv), 'ghost'))), ta, face) + }, + }) + + /* 朗读 */ + DB.tool({ + id: 'text-to-speech', name: '朗读文本', group: 'life', icon: 'bolt', desc: '用系统语音念出来,可选语速音高', keywords: ['tts', '朗读', '语音'], + mount(root) { + const ta = el('textarea', { class: 'ta', rows: 8, placeholder: '要朗读的文字' }) + const rate = el('input', { type: 'range', min: .5, max: 2, step: .1, value: 1 }) + const pitch = el('input', { type: 'range', min: .5, max: 2, step: .1, value: 1 }) + const speak = () => { if (!('speechSynthesis' in window)) { toast('这个浏览器不支持朗读', true); return } + speechSynthesis.cancel(); const u = new SpeechSynthesisUtterance(ta.value); u.rate = +rate.value; u.pitch = +pitch.value; u.lang = 'zh-CN'; speechSynthesis.speak(u) } + root.append(pane('朗读', el('div', { class: 'row' }, btn('朗读', speak), btn('停止', () => speechSynthesis.cancel(), 'ghost'), el('span', { text: '语速' }), rate, el('span', { text: '音高' }), pitch)), ta) + }, + }) + + /* 语音转文字 */ + DB.tool({ + id: 'speech-to-text', name: '语音转文字', group: 'life', icon: 'bolt', desc: '用浏览器语音识别,边说边转(Chrome / Edge)', keywords: ['语音识别', 'stt', '转写'], + mount(root) { + const out = el('pre', { class: 'out', text: '点开始后说话,支持中文' }) + const SR = window.SpeechRecognition || window.webkitSpeechRecognition + if (!SR) { out.textContent = '这个浏览器不支持语音识别(Chrome / Edge 可用)'; root.append(pane('语音转文字'), out); return } + let rec = null, text = '' + const start = () => { rec = new SR(); rec.lang = 'zh-CN'; rec.continuous = true; rec.interimResults = true + rec.onresult = (e) => { let t = ''; for (let i = e.resultIndex; i < e.results.length; i++) t += e.results[i][0].transcript; out.textContent = text + t } + rec.onend = () => { text = out.textContent; } + rec.start() } + root.append(pane('语音转文字', el('div', { class: 'row' }, btn('开始', start), btn('停', () => rec && rec.stop(), 'ghost'), btn('复制', () => DB.copy(out.textContent), 'ghost'))), out) + }, + }) + + /* 听力测试 */ + DB.tool({ + id: 'hearing-test', name: '听力频率测试', group: 'device', icon: 'bolt', desc: '从低频扫到高频,看你能听到多少 Hz(音量调小)', keywords: ['听力', '频率', 'hearing'], + mount(root) { + const face = el('div', { class: 'big-time', text: '—' }) + let ctx = null, osc = null + const play = (hz) => { ctx = ctx || new (window.AudioContext || window.webkitAudioContext)() + if (osc) { osc.stop(); osc.disconnect() } + osc = ctx.createOscillator(); const g = ctx.createGain(); osc.frequency.value = hz; g.gain.value = .06; osc.type = 'sine'; osc.connect(g); g.connect(ctx.destination); osc.start(); face.textContent = hz + ' Hz' } + root.append(pane('听力频率', btn('停止', () => { if (osc) { osc.stop(); osc.disconnect(); osc = null } }, 'ghost')), face, + el('div', { class: 'find-chips' }, ...[100, 250, 500, 1000, 2000, 4000, 6000, 8000, 12000, 16000, 18000].map((hz) => btn(hz + ' Hz', () => play(hz), 'ghost'))), + el('div', { class: 'hint', text: '成年人通常能听到 20Hz–16kHz,年龄越大高频越弱;音量请调小' })) + }, + }) + + /* 左右声道 */ + DB.tool({ + id: 'speaker-test', name: '左右声道测试', group: 'device', icon: 'bolt', desc: '分别只响左、右、双声道,检查耳机接线', keywords: ['声道', '耳机', '左右', 'speaker'], + mount(root) { + const play = (pan) => { const ctx = new (window.AudioContext || window.webkitAudioContext)(); const osc = ctx.createOscillator(); const p = ctx.createStereoPanner ? ctx.createStereoPanner() : null + const g = ctx.createGain(); g.gain.value = .12; osc.frequency.value = 440; osc.connect(g) + if (p) { p.pan.value = pan; g.connect(p); p.connect(ctx.destination) } else g.connect(ctx.destination) + osc.start(); setTimeout(() => { osc.stop(); ctx.close() }, 1200) } + root.append(pane('声道', el('div', { class: 'row' }, btn('左声道', () => play(-1)), btn('右声道', () => play(1)), btn('双声道', () => play(0)), btn('低频 60Hz', () => { const ctx = new (window.AudioContext || window.webkitAudioContext)(); const o = ctx.createOscillator(); const g = ctx.createGain(); g.gain.value = .1; o.frequency.value = 60; o.connect(g); g.connect(ctx.destination); o.start(); setTimeout(() => { o.stop(); ctx.close() }, 1200) }, 'ghost')))) + }, + }) + + /* 白噪音 */ + DB.tool({ + id: 'white-noise', name: '白噪音 / 雨声', group: 'life', icon: 'bolt', desc: '合成白噪、粉噪、雨声,帮助专注和入睡', keywords: ['白噪音', '雨声', '专注', '助眠'], + mount(root) { + let ctx = null, node = null, gain = null + const stop = () => { if (node) { try { node.stop ? node.stop() : node.disconnect() } catch (e) {} node = null } } + const play = (kind) => { stop(); ctx = ctx || new (window.AudioContext || window.webkitAudioContext)() + gain = gain || ctx.createGain(); gain.gain.value = .12; gain.connect(ctx.destination) + const len = ctx.sampleRate * 2; const buf = ctx.createBuffer(1, len, ctx.sampleRate); const d = buf.getChannelData(0) + let b0 = 0, b1 = 0, b2 = 0 + for (let i = 0; i < len; i++) { const w = Math.random() * 2 - 1 + if (kind === 'pink') { b0 = .99765 * b0 + w * .0990460; b1 = .96300 * b1 + w * .2965164; b2 = .57 * b2 + w * 1.0526913; d[i] = (b0 + b1 + b2 + w * .1848) * .12 } + else if (kind === 'rain') { d[i] = w * .55 + (Math.random() < .002 ? (Math.random() * 2 - 1) : 0) } + else d[i] = w * .6 } + node = ctx.createBufferSource(); node.buffer = buf; node.loop = true; node.connect(gain); node.start() } + root.append(pane('白噪音', el('div', { class: 'row' }, btn('白噪', () => play('white')), btn('粉噪', () => play('pink')), btn('雨声', () => play('rain')), btn('停止', stop, 'ghost')))) + }, + }) + + /* 节拍器 */ + DB.tool({ + id: 'metronome', name: '节拍器', group: 'device', icon: 'bolt', desc: 'BPM 可调,强拍有重音,练琴用', keywords: ['节拍器', 'bpm', '练琴'], + mount(root) { + const bpm = el('input', { type: 'range', min: 40, max: 220, value: 90 }) + const face = el('div', { class: 'big-time', text: '90 BPM' }) + let iv = 0, beat = 0 + const beep = (strong) => { const ctx = new (window.AudioContext || window.webkitAudioContext)(); const o = ctx.createOscillator(); const g = ctx.createGain() + o.frequency.value = strong ? 1200 : 800; g.gain.value = .18; o.connect(g); g.connect(ctx.destination); o.start(); setTimeout(() => { o.stop(); ctx.close() }, 60) } + const start = () => { clearInterval(iv); beat = 0 + iv = setInterval(() => { beep(beat % 4 === 0); face.textContent = `${bpm.value} BPM ${'●'.repeat(beat % 4 + 1)}${'○'.repeat(3 - beat % 4)}`; beat++ }, 60000 / +bpm.value) } + bpm.addEventListener('input', () => { face.textContent = bpm.value + ' BPM'; if (iv) start() }) + root.append(pane('节拍器', el('div', { class: 'row' }, bpm, btn('开始', start), btn('停', () => clearInterval(iv), 'ghost'))), face) + }, + }) + + /* 触摸测试 */ + DB.tool({ + id: 'touch-test', name: '多点触控测试', group: 'device', icon: 'box', desc: '看屏幕同时能识别几个手指,画点出来', keywords: ['触摸', '触控', 'touch'], + mount(root) { + const c = canvasOf(1200, 600); const g = c.getContext('2d') + if (!g) { root.append(el('p', { class: 'hint', text: '当前环境不支持 canvas,请在浏览器中使用' })); return } + g.fillStyle = '#151a23'; g.fillRect(0, 0, c.width, c.height) + const note = el('div', { class: 'hint', text: '把手指按在下面这块区域' }) + const draw = (e) => { e.preventDefault(); const r = c.getBoundingClientRect() + for (const t of e.touches) { const x = (t.clientX - r.left) * c.width / r.width, y = (t.clientY - r.top) * c.height / r.height + g.beginPath(); g.arc(x, y, 34, 0, 7); g.fillStyle = 'rgba(91,140,255,.65)'; g.fill(); g.fillStyle = '#fff'; g.font = '18px sans-serif'; g.textAlign = 'center'; g.fillText(t.identifier, x, y + 6) } + note.textContent = `同时 ${e.touches.length} 个触点` } + c.addEventListener('touchstart', draw, { passive: false }); c.addEventListener('touchmove', draw, { passive: false }) + c.addEventListener('mousedown', (e) => { const r = c.getBoundingClientRect(); g.beginPath(); g.arc((e.clientX - r.left) * c.width / r.width, (e.clientY - r.top) * c.height / r.height, 20, 0, 7); g.fillStyle = 'rgba(91,140,255,.65)'; g.fill() }) + root.append(pane('多点触控', btn('清空', () => { g.fillStyle = '#151a23'; g.fillRect(0, 0, c.width, c.height) }, 'ghost')), note, c) + }, + }) + + /* PPI 计算 */ + G({ id: 'ppi-checker', name: '屏幕 PPI 计算', group: 'device', icon: 'box', desc: '按分辨率与尺寸算像素密度与缩放比', keywords: ['ppi', '像素密度', '屏幕'], fields: [ + { key: 'w', label: '宽 px', type: 'number', value: 2560 }, { key: 'h', label: '高 px', type: 'number', value: 1440 }, { key: 'inch', label: '对角线 英寸', type: 'number', value: 27, step: .1 }], + run: ({ w, h, inch }) => { const ppi = Math.sqrt(w * w + h * h) / inch + return { text: `PPI:${ppi.toFixed(1)}\n点距:${(25.4 / ppi).toFixed(3)} mm\n建议缩放:${(ppi / 96 * 100).toFixed(0)}%(100% 基准 96 PPI)\n4K 27" 约 163 PPI,2K 27" 约 109 PPI` } } }) + + /* GPU 信息 */ + DB.tool({ + id: 'gpu-info', name: '显卡与 WebGL 信息', group: 'device', icon: 'box', desc: '看显卡型号、WebGL 版本、最大纹理尺寸', keywords: ['gpu', '显卡', 'webgl'], + mount(root) { + const out = el('pre', { class: 'out' }) + try { const c = document.createElement('canvas'); const gl = c.getContext('webgl2') || c.getContext('webgl') + if (!gl) { out.textContent = '这个浏览器没开 WebGL'; } else { const dbg = gl.getExtension('WEBGL_debug_renderer_info') + out.textContent = [`渲染器:${dbg ? gl.getParameter(dbg.UNMASKED_RENDERER_WEBGL) : gl.getParameter(gl.RENDERER)}`, `厂商:${dbg ? gl.getParameter(dbg.UNMASKED_VENDOR_WEBGL) : gl.getParameter(gl.VENDOR)}`, `版本:${gl.getParameter(gl.VERSION)}`, + `着色语言:${gl.getParameter(gl.SHADING_LANGUAGE_VERSION)}`, `最大纹理:${gl.getParameter(gl.MAX_TEXTURE_SIZE)}`, `最大 viewport:${[...gl.getParameter(gl.MAX_VIEWPORT_DIMS)].join(' × ')}`, `抗锯齿:${gl.getParameter(gl.SAMPLES)}x`].join('\n') } } + catch (e) { out.textContent = '读取失败:' + e.message } + root.append(pane('显卡信息'), out) + }, + }) + + /* 字体预览 */ + DB.tool({ + id: 'font-preview', name: '字体预览', group: 'web', icon: 'text', desc: '常见中英文字体效果对比,选字体配 CSS', keywords: ['字体', 'font', '预览'], + mount(root) { + const text = el('input', { class: 'input', type: 'text', value: '床前明月光 DevBox 123' }) + const box = el('div') + const paint = () => { box.textContent = '' + for (const f of ['system-ui', 'PingFang SC', 'Microsoft YaHei', 'SimSun', 'SimHei', 'KaiTi', 'Noto Sans SC', 'Menlo', 'monospace', 'serif']) { + box.append(el('div', { style: { fontFamily: f, fontSize: '22px', padding: '8px 0', borderBottom: '1px solid var(--line)' } }, el('div', { text: text.value }), el('div', { class: 'hint', text: f }))) } } + text.addEventListener('input', paint) + root.append(pane('字体预览'), text, box); paint() + }, + }) + + /* 字幕时间轴平移 */ + T({ id: 'subtitle-shift', name: '字幕时间轴平移', group: 'creator', icon: 'clock', desc: 'SRT 整体提前/延后 N 秒(正数延后)', keywords: ['字幕', 'srt', '平移', '字幕不同步'], ph: '1 00:00:02,000 --> 00:00:04,000\n你好\n\n(把整段 SRT 粘进来)', + fn: (s) => { const shift = 1.5 + const fmt = (ms) => { const h = Math.floor(ms / 3600000), m = Math.floor(ms % 3600000 / 60000), sec = Math.floor(ms % 60000 / 1000), ms2 = ms % 1000 + return `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}:${String(sec).padStart(2, '0')},${String(ms2).padStart(3, '0')}` } + const parse = (t) => { const m = /(\d+):(\d+):(\d+),(\d+)/.exec(t); return m ? (+m[1] * 3600 + +m[2] * 60 + +m[3]) * 1000 + +m[4] : 0 } + let n = 0 + const out = s.replace(/(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})/g, (_, a, b) => { n++; return `${fmt(parse(a) + shift * 1000)} --> ${fmt(parse(b) + shift * 1000)}` }) + return `${out}\n\n(已整体延后 ${shift} 秒,共处理 ${n} 条;要改偏移量就改本工具源码里的 shift)` } }) + + /* SRT ↔ VTT */ + T({ id: 'subtitle-convert', name: 'SRT ⇄ VTT 转换', group: 'creator', icon: 'swap', desc: '两种字幕格式互转,网页视频用 VTT', keywords: ['srt', 'vtt', '字幕'], ph: 'SRT 或 VTT 内容', + fn: (s) => { const isVtt = /^WEBVTT/.test(s.trim()) + if (isVtt) return s.replace(/^WEBVTT[^\n]*\n+/, '').replace(/(\d{2}:\d{2}:\d{2})\.(\d{3})/g, '$1,$2').trim() + return 'WEBVTT\n\n' + s.replace(/(\d{2}:\d{2}:\d{2}),(\d{3})/g, '$1.$2').trim() } }) + + /* ICS 日历 */ + G({ id: 'ics-tools', name: '生成 .ics 日历', group: 'office', icon: 'calendar', desc: '把日程生成可导入手机日历的文件', keywords: ['ics', '日历', '日程'], fields: [ + { key: 'title', label: '标题', type: 'text', value: '项目复盘会' }, { key: 'date', label: '日期', type: 'text', value: '2026-11-25' }, + { key: 'time', label: '开始时间', type: 'text', value: '14:00' }, { key: 'min', label: '时长(分)', type: 'number', value: 60 }], + run: ({ title, date, time, min }) => { const start = new Date(`${date}T${time}:00`); if (isNaN(start)) throw new Error('日期或时间写错') + const end = new Date(start.getTime() + min * 60000); const f = (d) => d.toISOString().replace(/[-:]/g, '').split('.')[0] + 'Z' + const ics = ['BEGIN:VCALENDAR', 'VERSION:2.0', 'PRODID:-//DevBox//CN', 'BEGIN:VEVENT', `UID:${Date.now()}@devbox`, `DTSTAMP:${f(new Date())}`, `DTSTART:${f(start)}`, `DTEND:${f(end)}`, `SUMMARY:${title}`, 'END:VEVENT', 'END:VCALENDAR'].join('\r\n') + downloadText('event.ics', ics) + return { text: ics, hint: '已下载 .ics,手机点开即可加日历' } } }) + + /* 红包/礼物交换 */ + G({ id: 'gift-exchange', name: '礼物交换配对', group: 'fun', icon: 'box', desc: '抽签式互送礼物,保证不抽到自己', keywords: ['礼物', '交换', '圣诞'], fields: [{ key: 'list', label: '名单', type: 'text', value: '张三\n李四\n王五\n赵六' }], + run: ({ list }) => { const l = list.split(/\n/).map((x) => x.trim()).filter(Boolean); if (l.length < 3) throw new Error('至少 3 个人') + let ok = false, map = null, guard = 0 + while (!ok && guard++ < 200) { const to = [...l].sort(() => Math.random() - .5); ok = l.every((n, i) => n !== to[i]); if (ok) map = to } + return { text: l.map((n, i) => `${n} → 送给 ${map[i]}`).join('\n'), hint: '没有自己送自己' } } }) + + /* 敏感词检查 */ + T({ id: 'sensitive-word-check', name: '敏感词自查', group: 'text', icon: 'shield', desc: '按常见违禁词表扫一遍,发布前自检', keywords: ['敏感词', '违禁', '审核'], ph: '把要发布的文案粘进来', + fn: (s) => { const W = ['最便宜', '第一', '国家级', '最佳', '顶级', '绝对', '100%有效', '永久', '包治', '根治', '特效', '秒杀全球', '稳赚', '保本', '日入过万', '刷单', '韭菜', '赌博', '代开发票', '办证'] + const hit = W.filter((w) => s.includes(w)) + return hit.length ? `发现 ${hit.length} 个提示词:\n${hit.map((w) => '· ' + w + '(位置 ' + s.indexOf(w) + ')').join('\n')}\n\n(广告法口径提示,仅供参考)` : '✓ 没命中内置词表(不代表平台审核一定通过)' } }) + + /* 信息提取 */ + T({ id: 'extract-emails', name: '提取邮箱', group: 'text', icon: 'text', desc: '从一大段文本里抠出所有邮箱并去重', keywords: ['邮箱', 'email', '提取'], ph: '粘贴含邮箱的文本', + fn: (s) => { const a = [...new Set(s.match(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g) || [])]; return a.length ? `${a.length} 个:\n${a.join('\n')}` : '没找到邮箱' } }) + T({ id: 'extract-links', name: '提取链接', group: 'text', icon: 'globe', desc: '抠出所有 http/https 链接并去重', keywords: ['链接', 'url', '提取'], ph: '粘贴含链接的文本', + fn: (s) => { const a = [...new Set(s.match(/https?:\/\/[^\s"'<>()]+/g) || [])]; return a.length ? `${a.length} 个:\n${a.join('\n')}` : '没找到链接' } }) + T({ id: 'extract-numbers', name: '提取数字', group: 'text', icon: 'hash', desc: '把文本里的所有数字抓出来,可求总和', keywords: ['数字', '提取', '求和'], ph: '一共 3 个苹果,2 个梨,花了 15.5 元', + fn: (s) => { const a = (s.match(/-?\d+(\.\d+)?/g) || []); const sum = a.reduce((x, y) => x + Number(y), 0) + return `共 ${a.length} 个数字:\n${a.join(' ')}\n\n求和:${+sum.toFixed(6)}` } }) + T({ id: 'extract-phones', name: '提取手机号', group: 'text', icon: 'hash', desc: '抠出大陆手机号并去重,支持打码', keywords: ['手机号', '电话', '提取'], ph: '联系 13812345678 或 13900001111', + fn: (s) => { const a = [...new Set(s.match(/(? x.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')).join('\n')}` : '没找到手机号' } }) + + /* slug */ + T({ id: 'slug-generator', name: 'URL 别名 slug', group: 'web', icon: 'globe', desc: '中文标题转 URL 友好别名(保留可读性)', keywords: ['slug', '别名', 'url'], ph: 'DevBox 工具箱 1.2 上线', + fn: (s) => s.trim().toLowerCase().replace(/[\s_]+/g, '-').replace(/[^\w\u4e00-\u9fa5-]/g, '').replace(/-+/g, '-').replace(/^-|-$/g, '') }) + + /* 花体字 */ + T({ id: 'fancy-text', name: '花体文字', group: 'text', icon: 'text', desc: '数学字母花体、圆体、粗体,昵称用', keywords: ['花体', '字体', '昵称'], ph: 'DevBox', + fn: (s) => { const MAP = { normal: (c) => c, bold: (c) => String.fromCodePoint(c.charCodeAt(0) + 0x1d3ff), italic: (c) => String.fromCodePoint(c.charCodeAt(0) + 0x1d3fd), script: (c) => String.fromCodePoint(c.charCodeAt(0) + 0x1d49b), mono: (c) => String.fromCodePoint(c.charCodeAt(0) + 0x1d697) } + const conv = (fn) => Array.from(s.toLowerCase()).map((c) => (/[a-z]/.test(c) ? fn(c) : c)).join('') + return ['bold', 'italic', 'script', 'mono'].map((k) => `${k.padEnd(7, ' ')} ${conv(MAP[k])}`).join('\n') } }) + + /* 小红书排版 */ + T({ id: 'xhs-format', name: '小红书排版', group: 'creator', icon: 'text', desc: '自动分段 + 加空行 + 表情符号,适合发笔记', keywords: ['小红书', '排版', '笔记'], ph: '把文案粘进来,自动排版', + fn: (s) => { const lines = s.split(/\n/).map((l) => l.trim()).filter(Boolean) + const emoji = ['✨', '🌿', '💡', '📌', '🌸', '🍀'] + return lines.map((l, i) => `${emoji[i % emoji.length]} ${l}`).join('\n\n') } }) +})()