265 lines
25 KiB
JavaScript
265 lines
25 KiB
JavaScript
(function () {
|
||
const { el, panelTitle, copy, toast } = DB
|
||
const pane = (t, ...k) => { const p = el('div', { class: 'panel' }); if (t) p.append(panelTitle(t)); p.append(...k.filter(Boolean)); return p }
|
||
const btn = (l, f, c = '') => el('button', { class: 'btn ' + c, text: l, onclick: f })
|
||
const stage = (h) => { const d = el('div', { class: 'fullscreen-stage' }); d.style.height = (h || 340) + 'px'; return d }
|
||
let ac = null
|
||
const audio = () => { ac = ac || new (window.AudioContext || window.webkitAudioContext)(); return ac }
|
||
|
||
/* 屏幕测试(纯色轮播) */
|
||
DB.tool({ id: 'screen-test', name: '屏幕测试', group: 'device', icon: 'monitor', desc: '纯色轮播,检查亮点、暗点、漏光', keywords: ['屏幕', '坏点', '漏光'],
|
||
mount(root) {
|
||
const colors = ['#ffffff', '#000000', '#ff0000', '#00ff00', '#0000ff', '#ffff00', '#00ffff', '#ff00ff']
|
||
const s = stage(); let i = 0
|
||
const paint = () => { s.style.background = colors[i]; s.textContent = '' ; s.append(el('span', { class: 'stage-hint', text: colors[i] + ' · 点一下换下一个' })) }
|
||
s.addEventListener('click', () => { i = (i + 1) % colors.length; paint() })
|
||
paint(); root.append(pane('屏幕测试', el('p', { class: 'hint', text: '手机调最亮,一个个看有没有异色点、边缘漏光。' })), s)
|
||
} })
|
||
|
||
DB.tool({ id: 'solid-color-screen', name: '纯色补光', group: 'device', icon: 'monitor', desc: '全屏纯白/纯色当补光灯', keywords: ['补光', '纯色', '白光'],
|
||
mount(root) {
|
||
const col = el('input', { type: 'color', value: '#ffffff' }); const s = stage(360)
|
||
const paint = () => { s.style.background = col.value }
|
||
col.addEventListener('input', paint); paint()
|
||
root.append(pane('纯色补光'), el('div', { class: 'row' }, col, btn('全屏', () => { s.requestFullscreen?.() }, 'ghost')), s)
|
||
} })
|
||
|
||
DB.tool({ id: 'monitor-calibration', name: '显示器校准', group: 'device', icon: 'monitor', desc: '灰阶、黑位、白位一张图调', keywords: ['校准', '灰阶', '对比度'],
|
||
mount(root) {
|
||
const box = el('div', { class: 'calib' })
|
||
for (let i = 0; i < 21; i++) { const d = el('div', { class: 'calib-cell' }); d.style.background = `rgb(${Math.round(i * 12.75)},${Math.round(i * 12.75)},${Math.round(i * 12.75)})`; box.append(d) }
|
||
const bar = el('div', { class: 'calib' })
|
||
;['#000', '#111', '#222', '#fff', '#eee', '#ddd', '#f00', '#0f0', '#00f', '#ff0', '#0ff', '#f0f'].forEach((c) => { const d = el('div', { class: 'calib-cell' }); d.style.background = c; bar.append(d) })
|
||
root.append(pane('显示器校准'), el('p', { class: 'hint', text: '第一排应能分辨每一格;最左黑块不该和背景融为一体,最右白块不该糊成一片。' }), box, bar)
|
||
} })
|
||
|
||
DB.tool({ id: 'color-banding-test', name: '色带测试', group: 'device', icon: 'monitor', desc: '看渐变有没有明显条纹', keywords: ['色带', '渐变', '色深'],
|
||
mount(root) {
|
||
const s = stage(300)
|
||
s.style.background = 'linear-gradient(90deg,#000 0%,#000 10%,#fff 90%,#fff 100%)'
|
||
const c = stage(300)
|
||
const g = c.getContext && c.getContext('2d')
|
||
if (g) { const grd = g.createLinearGradient(0, 0, c.clientWidth || 600, 0); grd.addColorStop(0, '#000'); grd.addColorStop(1, '#fff'); g.fillStyle = grd; g.fillRect(0, 0, c.clientWidth || 600, 300) }
|
||
root.append(pane('色带测试'), el('p', { class: 'hint', text: '平滑过渡为正常;出现明显竖条说明色深受限(8bit 屏常见)。' }), s, c)
|
||
} })
|
||
|
||
DB.tool({ id: 'color-arrangement-test', name: '颜色排序测试', group: 'device', icon: 'monitor', desc: '按色相排列小方块,练色感', keywords: ['色感', '排序', '颜色'],
|
||
mount(root) {
|
||
const wrap = el('div', { class: 'chips' }); const st = el('p', { class: 'hint', text: '点两个方块交换位置,排成彩虹顺序' })
|
||
let arr = [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330].sort(() => Math.random() - 0.5)
|
||
let sel = -1
|
||
const paint = () => { wrap.textContent = ''; arr.forEach((h, i) => { const d = el('button', { class: 'swatch' + (sel === i ? ' on' : '') }); d.style.background = `hsl(${h} 70% 55%)`; d.addEventListener('click', () => { if (sel < 0) sel = i; else { [arr[sel], arr[i]] = [arr[i], arr[sel]]; sel = -1; paint() } }); wrap.append(d) })
|
||
const ok = arr.every((v, i) => i === 0 || v > arr[i - 1]); st.textContent = ok ? '排对了 ✓' : '点两个方块交换位置,排成彩虹顺序' }
|
||
paint(); root.append(pane('颜色排序'), st, wrap, btn('重来', () => { arr = arr.sort(() => Math.random() - 0.5); paint() }, 'ghost'))
|
||
} })
|
||
|
||
DB.tool({ id: 'color-blind-test', name: '色觉自测', group: 'device', icon: 'monitor', desc: '简易色盲筛查图(红绿/蓝黄混淆)', keywords: ['色盲', '色弱', '色觉'],
|
||
mount(root) {
|
||
const s = stage(300); s.style.display = 'grid'; s.style.placeItems = 'center'
|
||
const plates = [['#e35d5d', '#7bb661', '8'], ['#5d7be3', '#d9c45b', '6'], ['#e3a95d', '#66b3a3', '3'], ['#8f5de3', '#5db67f', '5']]
|
||
let i = 0
|
||
const paint = () => { s.style.background = plates[i][0]; s.textContent = ''; const t = el('div', { text: plates[i][2] }); t.style.color = plates[i][1]; t.style.fontSize = '120px'; t.style.fontWeight = '800'; s.append(t) }
|
||
s.addEventListener('click', () => { i = (i + 1) % plates.length; paint() }); paint()
|
||
root.append(pane('色觉自测'), el('p', { class: 'hint', text: '能看到数字说明红绿色觉问题不大;看不清不代表一定有问题,只是筛查。点一下换一张。' }), s)
|
||
} })
|
||
|
||
DB.tool({ id: 'color-converter', name: '颜色转换', group: 'web', icon: 'palette', desc: 'HEX / RGB / HSL / HSV 互转,带对比度', keywords: ['颜色', 'hex', 'rgb', 'hsl'],
|
||
mount(root) {
|
||
const inp = el('input', { class: 'inp', value: '#3b82f6' })
|
||
const out = el('div', { class: 'kv-out', text: '' }); const sw = el('div', { class: 'swatch big' })
|
||
const parse = (s) => {
|
||
s = s.trim()
|
||
let m = s.match(/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i)
|
||
if (m) { let h = m[1]; if (h.length === 3) h = [...h].map((c) => c + c).join(''); return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16)] }
|
||
m = s.match(/rgba?\(([^)]+)\)/i)
|
||
if (m) return m[1].split(',').slice(0, 3).map((x) => +x.trim())
|
||
return null
|
||
}
|
||
const go = () => {
|
||
const rgb = parse(inp.value); if (!rgb) { out.textContent = '支持 #rrggbb 或 rgb(r,g,b)'; return }
|
||
const [r, g, b] = rgb.map((x) => Math.max(0, Math.min(255, Math.round(x))))
|
||
const hexv = '#' + [r, g, b].map((x) => x.toString(16).padStart(2, '0')).join('')
|
||
const max = Math.max(r, g, b) / 255, min = Math.min(r, g, b) / 255, l = (max + min) / 2
|
||
let h = 0, s2 = 0
|
||
if (max !== min) { const d = max - min; s2 = l > .5 ? d / (2 - max - min) : d / (max + min)
|
||
h = max === r / 255 ? ((g - b) / 255 / d + (g < b ? 6 : 0)) : max === g / 255 ? ((b - r) / 255 / d + 2) : ((r - g) / 255 / d + 4); h *= 60 }
|
||
const lum = [r, g, b].map((v) => { const c = v / 255; return c <= .03928 ? c / 12.92 : Math.pow((c + .055) / 1.055, 2.4) }).reduce((a, v, i) => a + v * [0.2126, 0.7152, 0.0722][i], 0)
|
||
sw.style.background = hexv
|
||
out.textContent = `HEX ${hexv}\nRGB rgb(${r}, ${g}, ${b})\nHSL hsl(${Math.round(h)}, ${Math.round(s2 * 100)}%, ${Math.round(l * 100)}%)\n相对亮度 ${lum.toFixed(3)} 对白字对比 ${((1.05) / (lum + 0.05)).toFixed(2)}:1 对黑字 ${((lum + 0.05) / 0.05).toFixed(2)}:1`
|
||
}
|
||
inp.addEventListener('input', go); go()
|
||
root.append(pane('颜色转换'), inp, el('div', { class: 'row' }, sw), out)
|
||
} })
|
||
|
||
DB.tool({ id: 'dominant-eye-test', name: '主视眼测试', group: 'device', icon: 'box', desc: '双手圈成三角看物体,判断主导眼', keywords: ['主视眼', '眼睛'],
|
||
mount(root) { root.append(pane('主视眼测试'), el('p', { class: 'hint', text: '1. 双手张开、虎口交叉成三角孔;2. 手臂伸直,透过孔看远处一个小物体;3. 保持不动分别闭左眼、闭右眼。还能看见物体的那只眼就是主视眼。' }), el('div', { class: 'kv-out', text: '射击、台球、摄影取景都可以用主视眼。' })) } })
|
||
|
||
DB.tool({ id: 'astigmatism-test', name: '散光自测', group: 'device', icon: 'box', desc: '放射状线条图,看是否粗细不一', keywords: ['散光', '视力'],
|
||
mount(root) {
|
||
const s = stage(340); const g = s.getContext && s.getContext('2d')
|
||
if (g) { const w = 600, h = 340; s.width = w; s.height = h; g.fillStyle = '#fff'; g.fillRect(0, 0, w, h); g.strokeStyle = '#111'; g.lineWidth = 2
|
||
for (let i = 0; i < 24; i++) { const a = (i / 24) * Math.PI * 2; g.beginPath(); g.moveTo(w / 2, h / 2); g.lineTo(w / 2 + Math.cos(a) * 150, h / 2 + Math.sin(a) * 150); g.stroke() } }
|
||
root.append(pane('散光自测'), el('p', { class: 'hint', text: '离屏 40cm 看,若某些方向的线明显更黑更粗,可能有散光(需去医院验光确认)。' }), s)
|
||
} })
|
||
|
||
DB.tool({ id: 'vision-test', name: '视力自测', group: 'device', icon: 'box', desc: 'E 字方向自测,粗略估视力', keywords: ['视力', '近视', '远视'],
|
||
mount(root) {
|
||
const s = stage(320), out = el('div', { class: 'kv-out', text: '' }), ans = el('div', { class: 'chips' })
|
||
let level = 0, correct = 0
|
||
const sizes = [120, 90, 64, 46, 32, 22, 14, 10]
|
||
const dirs = ['up', 'down', 'left', 'right']
|
||
let cur = 'up'
|
||
const paint = () => { s.textContent = ''; const t = el('div', { text: 'E' }); t.style.fontSize = sizes[level] + 'px'; t.style.fontWeight = '800'; t.style.transform = `rotate(${dirs.indexOf(cur) * 90}deg)`; s.style.display = 'grid'; s.style.placeItems = 'center'; s.append(t) }
|
||
const answer = (d) => { if (d === cur) correct++; level = Math.min(level + 1, sizes.length - 1); cur = dirs[Math.floor(Math.random() * 4)]; paint(); out.textContent = `已答对 ${correct} 题,当前字号 ${sizes[level]}px` }
|
||
answer('')
|
||
;['上', '下', '左', '右'].forEach((n, i) => ans.append(btn(n, () => answer(dirs[i]))))
|
||
root.append(pane('视力自测'), el('p', { class: 'hint', text: '手臂伸直(约 40cm)看屏幕,E 开口朝哪就点哪。' }), s, ans, out)
|
||
} })
|
||
|
||
DB.tool({ id: 'pwm-flicker-test', name: 'PWM 频闪检测', group: 'device', icon: 'monitor', desc: '转动的条纹看屏幕是否低频闪', keywords: ['频闪', 'pwm', '护眼'],
|
||
mount(root) {
|
||
const s = stage(220); const g = s.getContext && s.getContext('2d'); let x = 0, run = true
|
||
const loop = () => { if (!g) return; const w = s.width || 600, h = 220; s.width = w; s.height = h
|
||
g.fillStyle = '#fff'; g.fillRect(0, 0, w, h); g.fillStyle = '#000'
|
||
for (let i = -h; i < w + h; i += 24) { g.save(); g.translate(i + x, 0); g.rotate(0.35); g.fillRect(0, -h, 12, h * 3); g.restore() }
|
||
x = (x + 6) % 24; if (run) requestAnimationFrame(loop) }
|
||
loop(); s.addEventListener('click', () => { run = !run; if (run) loop() })
|
||
root.append(pane('PWM 频闪检测'), el('p', { class: 'hint', text: '滚动条纹出现明显分段/闪动,说明屏幕低频调光;点一下暂停。' }), s)
|
||
} })
|
||
|
||
DB.tool({ id: 'camera-test', name: '摄像头测试', group: 'device', icon: 'box', desc: '调用摄像头看画面是否正常', keywords: ['摄像头', '相机', 'camera'],
|
||
mount(root) {
|
||
const v = el('video', { class: 'cam', autoplay: true, playsinline: true, muted: true })
|
||
const st = el('p', { class: 'hint', text: '点开始授权摄像头' })
|
||
const start = async () => { try { const s = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' } }); v.srcObject = s; st.textContent = '已开启,点停止释放' } catch (e) { st.textContent = '打不开摄像头:' + e.message } }
|
||
root.append(pane('摄像头测试'), st, v, el('div', { class: 'row' }, btn('开始', start), btn('停止', () => { v.srcObject?.getTracks().forEach((t) => t.stop()); v.srcObject = null; st.textContent = '已停止' }, 'ghost')))
|
||
} })
|
||
|
||
DB.tool({ id: 'gps-test', name: 'GPS 测试', group: 'device', icon: 'box', desc: '看定位精度、坐标与速度', keywords: ['gps', '定位', '坐标'],
|
||
mount(root) {
|
||
const out = el('div', { class: 'kv-out', text: '点开始授权定位' })
|
||
const start = () => { if (!navigator.geolocation) { out.textContent = '这个浏览器不支持定位'; return }
|
||
navigator.geolocation.watchPosition((p) => { out.textContent = `纬度 ${p.coords.latitude.toFixed(6)}\n经度 ${p.coords.longitude.toFixed(6)}\n精度 ±${Math.round(p.coords.accuracy)} m\n海拔 ${p.coords.altitude ? Math.round(p.coords.altitude) + ' m' : '—'}\n速度 ${p.coords.speed ? (p.coords.speed * 3.6).toFixed(1) + ' km/h' : '—'}` },
|
||
(e) => { out.textContent = '定位失败:' + e.message }, { enableHighAccuracy: true }) }
|
||
root.append(pane('GPS 测试'), out, btn('开始', start))
|
||
} })
|
||
|
||
DB.tool({ id: 'sensor-test', name: '传感器测试', group: 'device', icon: 'box', desc: '看重力感应/陀螺仪读数', keywords: ['传感器', '陀螺仪', '加速计'],
|
||
mount(root) {
|
||
const out = el('div', { class: 'kv-out', text: '点开始读取设备方向' })
|
||
const on = (e) => { out.textContent = `α ${e.alpha?.toFixed(1) ?? '—'}° β ${e.beta?.toFixed(1) ?? '—'}° γ ${e.gamma?.toFixed(1) ?? '—'}°\n更新于 ${new Date().toLocaleTimeString()}` }
|
||
root.append(pane('传感器测试'), out, btn('开始', () => { window.addEventListener('deviceorientation', on); out.textContent = '已开始,转动手机看看读数' }), btn('停止', () => window.removeEventListener('deviceorientation', on), 'ghost'))
|
||
} })
|
||
|
||
DB.tool({ id: 'nkro-test', name: '按键同时识别测试', group: 'device', icon: 'keyboard', desc: '看键盘能同时识别几个键', keywords: ['键盘', 'nkro', '同时按键'],
|
||
mount(root) {
|
||
const out = el('div', { class: 'kv-out', text: '按住多个键试试' }); const set = new Set()
|
||
const dn = (e) => { set.add(e.code); out.textContent = `当前 ${set.size} 键:${[...set].join(' + ')} 最多 ${Math.max(set.size, +(out.dataset.max || 0))}`; out.dataset.max = Math.max(set.size, +(out.dataset.max || 0)) }
|
||
const up = (e) => { set.delete(e.code) }
|
||
window.addEventListener('keydown', dn); window.addEventListener('keyup', up)
|
||
root.append(pane('同时按键测试'), out, el('p', { class: 'hint', text: '普通键盘常见 6 键上限;机械键盘支持全键无冲。' }))
|
||
} })
|
||
|
||
DB.tool({ id: 'double-click-test', name: '双击速度测试', group: 'device', icon: 'mouse', desc: '测两次点击的间隔,判断鼠标微动是否双击', keywords: ['双击', '鼠标', '微动'],
|
||
mount(root) {
|
||
const pad = el('div', { class: 'clickpad', text: '在这里连续点' }); const out = el('div', { class: 'kv-out', text: '' }); let last = 0; const gaps = []
|
||
pad.addEventListener('click', () => { const t = performance.now(); if (last) { const g = Math.round(t - last); gaps.push(g); out.textContent = `间隔 ${g} ms 最近:${gaps.slice(-6).join(' / ')} ms\n${g < 40 ? '⚠ 间隔过短,可能是误触或双击' : ''}` } last = t })
|
||
root.append(pane('双击速度测试'), pad, out)
|
||
} })
|
||
|
||
DB.tool({ id: 'polling-rate-test', name: '鼠标轮询率', group: 'device', icon: 'mouse', desc: '快速移动鼠标,估算 1000Hz 还是 125Hz', keywords: ['轮询率', '鼠标', 'polling'],
|
||
mount(root) {
|
||
const out = el('div', { class: 'kv-out', text: '把鼠标在下面这块快速画圈' }); let times = []
|
||
const move = (e) => { times.push(performance.now()); if (times.length > 400) times.shift()
|
||
if (times.length > 20) { const span = times[times.length - 1] - times[0]; const hz = Math.round((times.length - 1) / span * 1000); out.textContent = `约 ${hz} Hz(样本 ${times.length})` } }
|
||
const pad = el('div', { class: 'clickpad', text: '在这里画圈' }); pad.addEventListener('pointermove', move)
|
||
root.append(pane('鼠标轮询率'), pad, out)
|
||
} })
|
||
|
||
/* 音频:声道 / 低频 / 耳鸣匹配 / 白噪音 / 雨声 / 专注音 */
|
||
DB.tool({ id: 'headphone-test', name: '耳机左右声道', group: 'device', icon: 'music', desc: '分别响左、右,检查耳机是否接反', keywords: ['耳机', '声道', '左右'],
|
||
mount(root) {
|
||
const play = (side) => { const ctx = audio(); const o = ctx.createOscillator(); const p = ctx.createStereoPanner?.() ; const g = ctx.createGain()
|
||
o.frequency.value = 440; g.gain.value = .2; o.connect(g); if (p) { p.pan.value = side === 'L' ? -1 : 1; g.connect(p); p.connect(ctx.destination) } else g.connect(ctx.destination)
|
||
o.start(); setTimeout(() => { o.stop() }, 900) }
|
||
root.append(pane('耳机左右声道'), el('div', { class: 'row' }, btn('左声道', () => play('L')), btn('右声道', () => play('R')), btn('居中', () => play('C'), 'ghost')), el('p', { class: 'hint', text: '左右相反说明耳机插头或系统设置被反相了。' }))
|
||
} })
|
||
|
||
DB.tool({ id: 'bass-test', name: '低频测试', group: 'device', icon: 'music', desc: '从 20Hz 扫到 200Hz,看下潜能到多低', keywords: ['低频', '低音', 'bass'],
|
||
mount(root) {
|
||
const out = el('div', { class: 'kv-out', text: '' }); let cur = null
|
||
const play = (f) => { stop(); const ctx = audio(); const o = ctx.createOscillator(); const g = ctx.createGain(); o.type = 'sine'; o.frequency.value = f; g.gain.value = .25; o.connect(g); g.connect(ctx.destination); o.start(); cur = { o, ctx }
|
||
out.textContent = `正在播放 ${f} Hz`; o.onended = () => { } }
|
||
const stop = () => { try { cur?.o.stop(); cur?.ctx.close() } catch (e) {} cur = null }
|
||
const row = el('div', { class: 'chips' }); [20, 30, 40, 50, 60, 80, 100, 120, 150, 200].forEach((f) => row.append(btn(f + 'Hz', () => play(f), 'ghost')))
|
||
root.append(pane('低频测试'), row, out, btn('停止', stop, 'ghost'), el('p', { class: 'hint', text: '20–40Hz 听不到很正常,耳机下潜一般到 40Hz。' }))
|
||
} })
|
||
|
||
DB.tool({ id: 'tinnitus-match', name: '耳鸣匹配', group: 'device', icon: 'music', desc: '找出跟你耳鸣最接近的音高', keywords: ['耳鸣', '音高', '匹配'],
|
||
mount(root) {
|
||
const out = el('div', { class: 'kv-out', text: '' }); let f = 4000, cur = null
|
||
const play = () => { try { cur?.o.stop(); cur?.ctx.close() } catch (e) {} const ctx = audio(); const o = ctx.createOscillator(), g = ctx.createGain(); o.frequency.value = f; g.gain.value = .08; o.connect(g); g.connect(ctx.destination); o.start(); cur = { o, ctx }; out.textContent = `当前 ${f} Hz` }
|
||
const slider = el('input', { type: 'range', min: 500, max: 12000, step: 50, value: f })
|
||
slider.addEventListener('input', () => { f = +slider.value; if (cur) play(); out.textContent = `当前 ${f} Hz` })
|
||
root.append(pane('耳鸣匹配'), slider, out, el('div', { class: 'row' }, btn('播放', play), btn('停止', () => { try { cur?.o.stop(); cur?.ctx.close() } catch (e) {} }, 'ghost')), el('p', { class: 'hint', text: '找到最接近的音高后,把这个数值带给耳鼻喉科医生参考。音量开小一点。' }))
|
||
} })
|
||
|
||
function noiseTool(id, name, desc, kind, keywords) {
|
||
DB.tool({ id, name, group: 'device', icon: 'music', desc, keywords, mount(root) {
|
||
const st = el('p', { class: 'hint', text: '未播放' }); let node = null, ctx = null
|
||
const start = () => { stop(); ctx = audio(); const len = ctx.sampleRate * 4; const buf = ctx.createBuffer(2, len, ctx.sampleRate)
|
||
for (let ch = 0; ch < 2; ch++) { const d = buf.getChannelData(ch); let b0 = 0, b1 = 0, b2 = 0
|
||
for (let i = 0; i < len; i++) { const w = Math.random() * 2 - 1
|
||
if (kind === 'white') d[i] = w * .18
|
||
else if (kind === 'pink') { b0 = .99765 * b0 + w * .099046; b1 = .963 * b1 + w * .2965164; b2 = .57 * b2 + w * 1.0526913; d[i] = (b0 + b1 + b2 + w * .1848) * .05 }
|
||
else d[i] = (Math.random() - .5) * Math.pow(Math.random(), 3) * 1.4 } }
|
||
node = ctx.createBufferSource(); node.buffer = buf; node.loop = true
|
||
const g = ctx.createGain(); g.gain.value = .5; node.connect(g); g.connect(ctx.destination); node.start(); st.textContent = '正在播放,音量可调小' }
|
||
const stop = () => { try { node?.stop(); ctx?.close() } catch (e) {} node = null; st.textContent = '已停止' }
|
||
root.append(pane(name), st, el('div', { class: 'row' }, btn('播放', start), btn('停止', stop, 'ghost')))
|
||
} })
|
||
}
|
||
noiseTool('white-noise', '白噪音', '屏蔽环境噪音,帮助入睡、专注', 'white', ['白噪音', '专注', '睡眠'])
|
||
noiseTool('rain-sounds', '雨声', '模拟雨滴声(合成)', 'rain', ['雨声', '助眠'])
|
||
noiseTool('focus-sounds', '粉噪音', '比白噪音更柔,适合长时间听', 'pink', ['粉噪', '专注'])
|
||
|
||
/* 呼吸 / 拉伸 / 眼保健 / 健身 */
|
||
DB.tool({ id: 'breathing-exercise', name: '呼吸引导', group: 'life', icon: 'sun', desc: '4-7-8 呼吸法,跟着圆呼吸', keywords: ['呼吸', '放松', '冥想'],
|
||
mount(root) {
|
||
const c = el('div', { class: 'breath-circle' }), st = el('div', { class: 'big-time', text: '准备' }); let iv = 0
|
||
const seq = [['吸气', 4], ['屏住', 7], ['呼气', 8]]
|
||
const run = () => { clearInterval(iv); let i = 0, left = seq[0][1]
|
||
const tick = () => { const [n, d] = seq[i]; st.textContent = n + ' ' + left; c.style.transform = `scale(${n === '吸气' ? 1.25 : n === '屏住' ? 1.25 : .85})`
|
||
left--; if (left <= 0) { i = (i + 1) % seq.length; left = seq[i][1] } }
|
||
tick(); iv = setInterval(tick, 1000) }
|
||
root.append(pane('4-7-8 呼吸'), st, c, el('div', { class: 'row' }, btn('开始', run), btn('停止', () => { clearInterval(iv); st.textContent = '已停止' }, 'ghost')))
|
||
} })
|
||
|
||
DB.tool({ id: 'stretch-routine', name: '久坐拉伸', group: 'life', icon: 'sun', desc: '一套 6 分钟办公室拉伸', keywords: ['拉伸', '久坐', '肩颈'],
|
||
mount(root) {
|
||
const list = [['颈部侧倾', '左右各 20 秒,耳朵靠近肩膀,不耸肩'], ['肩部环绕', '前后各 10 圈,动作慢'], ['胸椎伸展', '双手抱头,向后靠椅背 20 秒'], ['体侧伸展', '一手叉腰,另一手向对侧延伸,左右各 20 秒'], ['髋屈肌拉伸', '弓步前压,左右各 30 秒'], ['腿后侧拉伸', '伸直一条腿勾脚,身体前倾 30 秒'], ['手腕拉伸', '手指向下、向上各 15 秒'], ['眼球转动', '上下左右各 5 次,慢慢来']]
|
||
const box = el('div', { class: 'kv-out' }); box.textContent = list.map((a, i) => `${i + 1}. ${a[0]}:${a[1]}`).join('\n')
|
||
root.append(pane('久坐拉伸'), box)
|
||
} })
|
||
|
||
DB.tool({ id: 'eye-exercise', name: '眼保健操', group: 'life', icon: 'sun', desc: '20-20-20 之外的眼部放松动作', keywords: ['眼保健操', '护眼'],
|
||
mount(root) {
|
||
const s = [['远眺', '看 6 米外固定物体 20 秒'], ['眨眼', '快速眨眼 15 次,再闭眼 10 秒'], ['眼球画圈', '顺时针、逆时针各 5 圈'], ['掌心捂眼', '双手搓热捂眼 30 秒,不要压眼球'], ['交替聚焦', '手指 20cm 与远处交替看 10 次']]
|
||
root.append(pane('眼保健操'), el('div', { class: 'kv-out', text: s.map((a, i) => `${i + 1}. ${a[0]}:${a[1]}`).join('\n') }))
|
||
} })
|
||
|
||
DB.tool({ id: 'workout-random', name: '随机训练', group: 'life', icon: 'sun', desc: '随机抽一个居家动作组合', keywords: ['健身', '训练', '随机'],
|
||
mount(root) {
|
||
const moves = ['深蹲 15 次', '俯卧撑 10 次', '平板支撑 30 秒', '开合跳 30 次', '登山跑 20 次', '臀桥 15 次', '靠墙静蹲 45 秒', '弓步蹲 12 次/侧', '卷腹 15 次', '波比跳 8 次']
|
||
const out = el('div', { class: 'kv-out big', text: '' })
|
||
const go = () => { out.textContent = [...moves].sort(() => Math.random() - .5).slice(0, 4).map((m, i) => `${i + 1}. ${m}`).join('\n') + '\n\n完成 3 轮,组间休息 60 秒' }
|
||
go(); root.append(pane('随机训练'), out, btn('换一组', go))
|
||
} })
|
||
|
||
DB.tool({ id: 'first-aid-guide', name: '急救速查', group: 'life', icon: 'info', desc: '常见意外的第一步处理(不含诊断)', keywords: ['急救', '烫伤', '扭伤'],
|
||
mount(root) {
|
||
const items = [['烫伤', '立刻用流动凉水冲 15–20 分钟,不要涂牙膏酱油,起泡不要挑破'], ['割伤', '清水冲洗,干净纱布压迫止血 10 分钟,深的伤口去医院'], ['扭伤', '前 48 小时冰敷每次 15 分钟,抬高患处,别热敷别揉'], ['异物卡喉', '成人海姆立克:背后抱住,拳头顶脐上快速向上冲击'], ['中暑', '移到阴凉处,解开衣物,凉水擦身,意识不清立刻急救'], ['低血糖', '意识清醒时吃 15g 糖(半罐可乐/3 块方糖),15 分钟复测']]
|
||
root.append(pane('急救速查'), el('div', { class: 'kv-out', text: items.map(([a, b]) => `· ${a}:${b}`).join('\n') }), el('p', { class: 'hint', text: '以上只是常识提示,严重情况请立刻拨打 120。' }))
|
||
} })
|
||
})()
|