文本提取器:结果按规则分组,逐条可单独复制

- 结果从单个 <pre> 改成 .extract-group 分组列表,每组头显示「手机号 · 2 条」与「复制全部」
- 每条一行:值 + 独立「复制」按钮,移动端自动换行
- 样式补充 .chips/.chip-btn/.extract-head/.extract-row/.extract-val
This commit is contained in:
gitea committed 2026-11-20 14:32:45 +08:00
1 parent 80ecd02bfa
commit cea0c44e9d
2 files changed
+30 -6

No files matched your search

+16 -6
View File
@@ -26,7 +26,7 @@
const src = ta('把一整段文本粘进来…', 12)
const picks = new Set(['phone', 'email', 'url'])
const chips = el('div', { class: 'chips' })
const out = el('pre', { class: 'out' })
const out = el('div', { class: 'extract-out' })
const counts = el('div', { class: 'hint' })
for (const [k, r] of Object.entries(RULES)) {
const chip = el('button', { class: 'chip-btn' + (picks.has(k) ? ' on' : ''), text: r.name + ' · ' + r.hint })
@@ -39,17 +39,27 @@
}
const run = () => {
const text = src.value
if (!text.trim()) { out.textContent = ''; counts.textContent = ''; return }
const blocks = []
out.textContent = ''
if (!text.trim()) { counts.textContent = ''; return }
let total = 0
for (const k of Object.keys(RULES)) {
if (!picks.has(k)) continue
const found = [...new Set(text.match(RULES[k].re) || [])]
if (!found.length) continue
total += found.length
if (found.length) blocks.push(`# ${RULES[k].name}(${found.length})\n` + found.join('\n'))
const box = el('div', { class: 'extract-group' })
box.append(el('div', { class: 'row between extract-head' },
el('b', { text: RULES[k].name + ' · ' + found.length + ' 条' }),
el('button', { class: 'btn tiny ghost', text: '复制全部', onclick: () => copy(found.join('\n')) })))
for (const item of found) {
box.append(el('div', { class: 'extract-row' },
el('code', { class: 'extract-val', text: item }),
el('button', { class: 'btn tiny', text: '复制', onclick: () => copy(item) })))
}
out.append(box)
}
out.textContent = blocks.join('\n\n') || '这些规则都没有匹配到内容'
counts.textContent = `共 ${total} 条,已去重`
if (!total) out.append(el('div', { class: 'hint', text: '这些规则都没有匹配到内容' }))
counts.textContent = total ? `共 ${total} 条,已去重` : ''
}
root.append(
pane('要抓什么', el('div', { class: 'row' }, btn('全选', () => { Object.keys(RULES).forEach((k) => picks.add(k)); root.querySelectorAll('.chip-btn').forEach((c) => c.classList.add('on')); run() }, 'ghost'), btn('只留链接', () => { picks.clear(); picks.add('url'); root.querySelectorAll('.chip-btn').forEach((c, i) => c.classList.toggle('on', Object.keys(RULES)[i] === 'url')); run() }, 'ghost'))),