Files
gitea f454ea8da7 首页加分类小按钮 + 参照 deertools 扩到 201 个工具
- app.js: 首页粘性搜索条 + 分类 chip(带数量),实时过滤,不再翻半天
- 新增 lib-simple.js(textTool / convTool / genTool 工厂)
- 新增 9 个 catalog:cat-text / cat-encode / cat-convert / cat-random / cat-dev / cat-css / cat-device / cat-office / cat-life
- 新增分组:随机 / 检测 / 办公 / 生活
- 工具数 44 → 201;全部 mount 通过(jsdom 201/201)
2026-11-20 14:50:14 +08:00

87 lines
13 KiB
JavaScript
Raw Permalink 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 · 开发与站点相关 */
(function () {
'use strict'
const { textTool: T, genTool: G } = DB
T({ id: 'http-status-codes', name: 'HTTP 状态码', group: 'web', icon: 'globe', desc: '常见状态码含义与什么时候用,随手查', keywords: ['http', 'status', '状态码'], ph: '输入 404 或留空看全部',
fn: (s) => { const M = { 200: '成功', 201: '已创建', 204: '成功但无内容', 301: '永久重定向', 302: '临时重定向', 304: '缓存未修改', 307: '临时重定向(保留方法)', 400: '请求错误', 401: '未认证', 403: '无权限', 404: '找不到', 405: '方法不允许', 408: '请求超时', 409: '冲突', 413: '请求体太大', 415: '媒体类型不支持', 422: '参数校验失败', 429: '请求太频繁', 500: '服务器内部错误', 502: '网关错误', 503: '服务不可用', 504: '网关超时' }
const k = s.trim(); return k && M[k] ? `${k} ${M[k]}` : Object.entries(M).map(([c, m]) => `${c} ${m}`).join('\n') } })
T({ id: 'mime-types', name: 'MIME 类型查询', group: 'web', icon: 'code', desc: '扩展名 ↔ MIME 类型,配 nginx、上传白名单用', keywords: ['mime', '类型', 'content-type'], ph: 'png 或 image/jpeg',
fn: (s) => { const M = { jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png', gif: 'image/gif', webp: 'image/webp', avif: 'image/avif', svg: 'image/svg+xml', ico: 'image/x-icon', mp4: 'video/mp4', webm: 'video/webm', mov: 'video/quicktime', mp3: 'audio/mpeg', wav: 'audio/wav', ogg: 'audio/ogg', flac: 'audio/flac', pdf: 'application/pdf', zip: 'application/zip', rar: 'application/vnd.rar', '7z': 'application/x-7z-compressed', tar: 'application/x-tar', gz: 'application/gzip', doc: 'application/msword', docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', xls: 'application/vnd.ms-excel', xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ppt: 'application/vnd.ms-powerpoint', pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation', json: 'application/json', xml: 'application/xml', html: 'text/html', css: 'text/css', js: 'text/javascript', mjs: 'text/javascript', txt: 'text/plain', csv: 'text/csv', md: 'text/markdown', ttf: 'font/ttf', otf: 'font/otf', woff: 'font/woff', woff2: 'font/woff2', eot: 'application/vnd.ms-fontobject', wasm: 'application/wasm', apk: 'application/vnd.android.package-archive', ipa: 'application/octet-stream' }
const k = s.trim().toLowerCase().replace(/^\./, '')
if (!k) return Object.entries(M).map(([e, m]) => `${e.padEnd(6, ' ')} ${m}`).join('\n')
if (M[k]) return `${k} → ${M[k]}`
const hit = Object.entries(M).find(([, m]) => m === k)
return hit ? `${k} → .${hit[0]}` : '没查到这个类型' } })
T({ id: 'file-extension-lookup', name: '文件扩展名解释', group: 'web', icon: 'box', desc: '看到奇怪后缀不知道是什么?这里查', keywords: ['extension', '扩展名', '后缀'], ph: 'webp / log',
fn: (s) => { const M = { webp: 'Google 的图片格式,比 jpg 小 30%', avif: '新一代图片格式,压缩率最高之一', heic: '苹果手机默认照片格式', svg: '矢量图,本质是文本', wasm: 'WebAssembly 二进制模块', mjs: 'ES Module 形式的 JS', cjs: 'CommonJS 模块', ts: 'TypeScript 源码', tsx: '带 JSX 的 TypeScript', jsx: '带 JSX 的 JavaScript', lock: '依赖锁文件,别手改', map: 'Source Map,调试用', dmg: 'macOS 安装镜像', apk: '安卓安装包', ipa: 'iOS 安装包', deb: 'Debian/Ubuntu 安装包', rpm: 'RedHat 系安装包', tar: '打包(不压缩)', gz: 'gzip 压缩', br: 'brotli 压缩', zst: 'zstd 压缩', iso: '光盘镜像', vcf: '通讯录 vCard', epub: '电子书格式', mobi: '老 Kindle 电子书' }
const k = s.trim().toLowerCase().replace(/^\./, ''); return M[k] ? `.${k}:${M[k]}` : Object.entries(M).map(([e, d]) => `${e.padEnd(6, ' ')} ${d}`).join('\n') } })
T({ id: 'user-agent-parser', name: 'User-Agent 解析', group: 'web', icon: 'globe', desc: '把 UA 拆成浏览器、内核、系统、设备,看日志方便', keywords: ['ua', 'user-agent', '浏览器'], ph: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 Version/17.0 Mobile/15E148 Safari/604.1',
fn: (s) => { const ua = s.trim(); if (!ua) return '把 UA 粘进来'
const os = /Windows NT 10/.test(ua) ? 'Windows 10/11' : /Windows NT/.test(ua) ? 'Windows' : /iPhone|iPad/.test(ua) ? 'iOS' : /Mac OS X/.test(ua) ? 'macOS' : /Android/.test(ua) ? 'Android ' + (/Android ([\d.]+)/.exec(ua)?.[1] || '') : /Linux/.test(ua) ? 'Linux' : '未知'
const br = /Edg\//.test(ua) ? 'Edge' : /OPR\//.test(ua) ? 'Opera' : /Firefox\//.test(ua) ? 'Firefox' : /Chrome\//.test(ua) ? 'Chrome' : /Safari\//.test(ua) ? 'Safari' : '未知'
const eng = /AppleWebKit/.test(ua) && /Chrome/.test(ua) ? 'Blink' : /Gecko\//.test(ua) && !/like Gecko/.test(ua) ? 'Gecko' : /AppleWebKit/.test(ua) ? 'WebKit' : '未知'
const dev = /iPad/.test(ua) ? '平板' : /Mobile/.test(ua) ? '手机' : '桌面'
return [`浏览器:${br} ${(/Chrome\/([\d.]+)/.exec(ua) || /Version\/([\d.]+)/.exec(ua) || /Firefox\/([\d.]+)/.exec(ua) || [])[1] || ''}`, `内核:${eng}`, `系统:${os}`, `设备:${dev}`, `长度:${ua.length} 字符`].join('\n') } })
T({ id: 'gitignore-generator', name: '.gitignore 生成', group: 'web', icon: 'code', desc: '按技术栈给一份现成的忽略规则,省得漏 node_modules', keywords: ['gitignore', 'git', '忽略'], ph: 'node python mac',
fn: (s) => { const S = { node: ['node_modules/', 'dist/', '.next/', '.nuxt/', 'npm-debug.log*', 'pnpm-debug.log*', '.env*.local'], python: ['__pycache__/', '*.py[cod]', '.venv/', 'venv/', '*.egg-info/', '.pytest_cache/'], java: ['target/', '*.class', '*.jar', '!.mvn/wrapper/maven-wrapper.jar'], go: ['bin/', '*.exe', '*.test', 'vendor/'], mac: ['.DS_Store', '.AppleDouble'], ide: ['.idea/', '.vscode/', '*.iml'], os: ['Thumbs.db', 'Desktop.ini'], env: ['.env', '.env.*', '!.env.example'], log: ['*.log', 'logs/'] }
const pick = s.toLowerCase().trim().split(/[\s,]+/).filter(Boolean); const keys = pick.length ? pick.filter((k) => S[k]) : Object.keys(S)
return ['# 由 DevBox 生成'].concat(...keys.map((k) => ['', `# ${k}`, ...S[k]])).join('\n') } })
T({ id: 'sitemap-generator', name: 'sitemap.xml 生成', group: 'web', icon: 'globe', desc: '一行一个 URL,生成标准 sitemap', keywords: ['sitemap', 'seo', '站点地图'], ph: 'https://a.com/\nhttps://a.com/about',
fn: (s) => { const list = s.split(/\r?\n/).map((x) => x.trim()).filter(Boolean)
if (!list.length) throw new Error('先输入网址,一行一个')
return '<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' +
list.map((u) => ` <url>\n <loc>${u}</loc>\n <changefreq>weekly</changefreq>\n <priority>0.8</priority>\n </url>`).join('\n') + '\n</urlset>' } })
T({ id: 'robots-generator', name: 'robots.txt 生成', group: 'web', icon: 'globe', desc: '允许/禁止路径 + sitemap 地址,生成标准 robots', keywords: ['robots', 'seo'], ph: '禁止:/admin\n允许:/\nsitemap:https://a.com/sitemap.xml',
fn: (s) => { const dis = [...s.matchAll(/禁止[::]\s*(\S+)/g)].map((m) => m[1]); const allow = [...s.matchAll(/允许[::]\s*(\S+)/g)].map((m) => m[1]); const sm = /sitemap[::]\s*(\S+)/i.exec(s)?.[1]
return ['User-agent: *', ...allow.map((x) => `Allow: ${x}`), ...dis.map((x) => `Disallow: ${x || '/'}`), ...(sm ? ['', `Sitemap: ${sm}`] : [])].join('\n') } })
T({ id: 'meta-generator', name: '网页 Meta 生成', group: 'web', icon: 'code', desc: '生成 SEO / 微信 / Twitter 卡片用的 meta 标签', keywords: ['meta', 'seo', 'og'], ph: '标题 | 描述 | https://a.com | https://a.com/i.png',
fn: (s) => { const [title = '', desc = '', url = '', img = ''] = s.split('|').map((x) => x.trim())
return [`<title>${title}</title>`, `<meta name="description" content="${desc}">`, `<link rel="canonical" href="${url}">`,
`<meta property="og:type" content="website">`, `<meta property="og:title" content="${title}">`, `<meta property="og:description" content="${desc}">`,
`<meta property="og:url" content="${url}">`, img ? `<meta property="og:image" content="${img}">` : '',
`<meta name="twitter:card" content="summary_large_image">`, `<meta name="twitter:title" content="${title}">`, `<meta name="twitter:description" content="${desc}">`].filter(Boolean).join('\n') } })
T({ id: 'browser-info', name: '浏览器信息', group: 'web', icon: 'globe', desc: '当前浏览器的 UA、语言、屏幕、像素比、时区', keywords: ['browser', 'info', '环境'], ph: '(结果自动给出)',
fn: () => [`UA:${navigator.userAgent}`, `语言:${navigator.language} / ${(navigator.languages || []).join(', ')}`, `平台:${navigator.platform || '-'}`,
`屏幕:${screen.width}×${screen.height},可用 ${screen.availWidth}×${screen.availHeight}`, `窗口:${innerWidth}×${innerHeight},像素比 ${devicePixelRatio}`,
`色彩深度:${screen.colorDepth} 位`, `时区:${Intl.DateTimeFormat().resolvedOptions().timeZone}(UTC${new Date().getTimezoneOffset() > 0 ? '-' : '+'}${Math.abs(new Date().getTimezoneOffset() / 60)})`,
`CPU 核心:${navigator.hardwareConcurrency || '未知'}`, `内存:${navigator.deviceMemory || '未知'} GB`, `触屏:${navigator.maxTouchPoints || 0} 点`, `Cookie 可用:${navigator.cookieEnabled ? '是' : '否'}`].join('\n') })
T({ id: 'network-info', name: '网络信息', group: 'web', icon: 'globe', desc: '连接类型、下上行速度、RTT、是否省流量', keywords: ['network', '网络', '网速'], ph: '(结果自动给出)',
fn: () => { const c = navigator.connection || {}; return [`在线:${navigator.onLine ? '是' : '否'}`, `类型:${c.effectiveType || '未知'}`, `下行:${c.downlink ? c.downlink + ' Mbps' : '未知'}`,
`RTT:${c.rtt != null ? c.rtt + ' ms' : '未知'}`, `省流量模式:${c.saveData ? '开' : '关'}`, `本机时区偏移:UTC${-new Date().getTimezoneOffset() / 60}`].join('\n') } })
T({ id: 'screen-resolution', name: '屏幕与设备分辨率', group: 'web', icon: 'box', desc: '查屏幕尺寸、可视区域、DPR,做适配时看这个', keywords: ['screen', 'resolution', '分辨率'], ph: '(结果自动给出)',
fn: () => [`屏幕:${screen.width} × ${screen.height}`, `可用:${screen.availWidth} × ${screen.availHeight}`, `视口:${innerWidth} × ${innerHeight}`, `设备像素比:${devicePixelRatio}`,
`物理像素:${Math.round(screen.width * devicePixelRatio)} × ${Math.round(screen.height * devicePixelRatio)}`, `方向:${screen.orientation?.type || '-'}`, `触控点:${navigator.maxTouchPoints || 0}`].join('\n') })
T({ id: 'paper-size', name: '纸张尺寸', group: 'office', icon: 'box', desc: 'A/B/C 系列与常见照片尺寸(mm / 像素 @300dpi)', keywords: ['paper', 'a4', '纸张', '打印'], ph: '输入 A4 或留空看全部',
fn: (s) => { const MM = { A0: [841, 1189], A1: [594, 841], A2: [420, 594], A3: [297, 420], A4: [210, 297], A5: [148, 210], A6: [105, 148], B5: [176, 250], Letter: [216, 279], Legal: [216, 356], '1寸照片': [25, 35], '2寸照片': [35, 49], '名片': [90, 54] }
const k = s.trim().toUpperCase(); const one = (n) => { const [w, h] = MM[n]; return `${n.padEnd(8, ' ')} ${w}×${h} mm ${Math.round(w / 25.4 * 300)}×${Math.round(h / 25.4 * 300)} px @300dpi` }
return k && MM[k] ? one(k) : Object.keys(MM).map(one).join('\n') } })
T({ id: 'keycode-checker', name: '按键码查询', group: 'web', icon: 'terminal', desc: '按下任意键,显示 key / code / keyCode,写键盘逻辑用', keywords: ['keycode', '按键', '键盘'], ph: '点这里再按键(结果在下面)',
fn: () => '点一下输入框,然后按键,这里显示 key / code / keyCode' })
document.getElementById('view')?.addEventListener('keydown', (e) => { DB.toast(`key=${e.key} code=${e.code} keyCode=${e.keyCode}`) })
G({ id: 'placeholder-image', name: '占位图生成', group: 'image', icon: 'image', desc: '指定尺寸与文字生成 PNG 占位图,直接下载', keywords: ['placeholder', '占位图', 'mock'], fields: [
{ key: 'w', label: '宽', type: 'number', value: 600, min: 16, max: 4000 }, { key: 'h', label: '高', type: 'number', value: 400, min: 16, max: 4000 },
{ key: 'text', label: '文字', type: 'text', value: 'DevBox' }, { key: 'bg', label: '底色', type: 'text', value: '#1f2430' }],
run: ({ w, h, text, bg }) => { const c = document.createElement('canvas'); c.width = w; c.height = h
const g = c.getContext('2d'); g.fillStyle = bg; g.fillRect(0, 0, w, h)
g.strokeStyle = 'rgba(255,255,255,.18)'; g.lineWidth = 2; for (let x = 0; x < w; x += 40) { g.beginPath(); g.moveTo(x, 0); g.lineTo(x, h); g.stroke() } for (let y = 0; y < h; y += 40) { g.beginPath(); g.moveTo(0, y); g.lineTo(w, y); g.stroke() }
g.fillStyle = '#fff'; g.font = `600 ${Math.max(14, Math.min(w, h) / 8)}px sans-serif`; g.textAlign = 'center'; g.textBaseline = 'middle'; g.fillText(text, w / 2, h / 2)
g.font = '13px monospace'; g.fillStyle = 'rgba(255,255,255,.7)'; g.fillText(`${w} × ${h}`, w / 2, h / 2 + Math.max(24, Math.min(w, h) / 8))
const url = c.toDataURL('image/png')
DB.download(`placeholder-${w}x${h}.png`, url)
return { text: `已生成并开始下载 ${w}×${h}(也可右键上图另存)\n${url.slice(0, 60)}…`, hint: 'PNG 已触发下载' } } })
})()