- cat-board.js: 待办、便利贴、看板、习惯打卡、心情记录、SWOT、甘特、组织架构、 值班表、签到表、课程表、行李清单、人生日历、闪卡、方格纸(localStorage 持久化) - cat-misc.js: 白板、签名板、代码转图、LED 字幕、提词器、速读、语音合成/识别、 听力/声道测试、白噪音、节拍器、触摸/PPI/GPU/字体预览、字幕位移与 SRT⇄VTT、 .ics 日历、礼物交换、敏感词、邮箱/链接/号码提取、slug、花体字、小红书排版
325 lines
28 KiB
JavaScript
325 lines
28 KiB
JavaScript
/* 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(/(?<!\d)1[3-9]\d{9}(?!\d)/g) || [])]
|
||
return a.length ? `${a.length} 个:\n${a.join('\n')}\n\n打码版:\n${a.map((x) => 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') } })
|
||
})()
|