feat: document scanner — scan file uploads for PPI before sending

New module: document-scanner.js
- PDF: extracts text from content streams, scans for PPI, converts to
  sanitized plaintext for upload (PDFs can't be reliably edited in-place)
- DOCX/XLSX: extracts text from XML entries, scans for PPI
- Text files: direct string substitution
- Handles scanned/image-only PDFs gracefully (skips with message)

Fetch interceptor (content.js):
- Now intercepts FormData uploads (file uploads) in addition to JSON
- Processes each file through document scanner
- Preview mode for PDF/DOCX/XLSX: shows PPI findings with counts,
  user clicks "Substitute & Upload" or "Upload Original"
- Text files substituted silently (no preview friction)
- String form fields also substituted
- 30-second auto-dismiss on preview (uploads original if no response)

Preview UI (content.css):
- Centered overlay with dark theme matching existing warning UI
- Shows original → substituted pairs for each PPI found
- File format note (e.g. "PDF will be converted to plain text")

https://claude.ai/code/session_01SWSwDfMVij53bCTNSCLMwn
This commit is contained in:
Claude
2026-03-26 20:27:27 +00:00
parent e4b44a73ea
commit 6598587bc4
3 changed files with 988 additions and 21 deletions
+110
View File
@@ -244,3 +244,113 @@
opacity: 1;
transform: translateY(0);
}
/* Document scan preview overlay */
.ss-doc-preview {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(0.95);
max-width: 480px;
width: 90vw;
background: #1a1a1a;
color: #e5e7eb;
border: 1px solid #f59e0b;
border-radius: 12px;
padding: 16px 20px;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
font-size: 12px;
z-index: 9999999;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
opacity: 0;
pointer-events: none;
transition: opacity 0.2s, transform 0.2s;
max-height: 70vh;
overflow-y: auto;
}
.ss-doc-preview.visible {
opacity: 1;
transform: translate(-50%, -50%) scale(1);
pointer-events: auto;
}
.ss-dp-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.ss-dp-count {
font-size: 11px;
color: #f59e0b;
font-weight: 600;
}
.ss-dp-note {
font-size: 11px;
color: #9ca3af;
margin-bottom: 10px;
font-style: italic;
}
.ss-dp-items {
max-height: 200px;
overflow-y: auto;
margin-bottom: 12px;
}
.ss-dp-item {
display: flex;
align-items: center;
gap: 6px;
padding: 4px 0;
border-bottom: 1px solid #333;
font-size: 11px;
}
.ss-dp-item:last-child { border-bottom: none; }
.ss-dp-orig {
color: #f87171;
background: #1f1f1f;
padding: 2px 5px;
border-radius: 3px;
}
.ss-dp-repl {
color: #4ade80;
background: #1f1f1f;
padding: 2px 5px;
border-radius: 3px;
}
.ss-dp-actions {
display: flex;
gap: 8px;
}
.ss-dp-btn {
flex: 1;
padding: 8px 12px;
border: none;
border-radius: 6px;
font-size: 12px;
font-weight: 500;
cursor: pointer;
}
.ss-dp-confirm {
background: #10b981;
color: #fff;
}
.ss-dp-confirm:hover { background: #059669; }
.ss-dp-cancel {
background: #374151;
color: #e5e7eb;
}
.ss-dp-cancel:hover { background: #4b5563; }