-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
75 lines (73 loc) · 3.43 KB
/
index.html
File metadata and controls
75 lines (73 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="theme-color" content="#070910">
<meta name="description" content="Nabu - Speed Reading App">
<title>Nabu</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.0.379/pdf.min.mjs" type="module"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script type="module">
// Initialize PDF.js worker
import * as pdfjsLib from 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.0.379/pdf.min.mjs';
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.0.379/pdf.worker.min.mjs';
window.pdfjsLib = pdfjsLib;
// PDF text extraction function
window.extractPdfText = async function(arrayBuffer) {
try {
const pdf = await pdfjsLib.getDocument({ data: arrayBuffer }).promise;
let fullText = '';
for (let i = 1; i <= pdf.numPages; i++) {
const page = await pdf.getPage(i);
const textContent = await page.getTextContent();
const pageText = textContent.items.map(item => item.str).join(' ');
fullText += pageText + '\n';
}
return fullText.trim();
} catch (e) {
throw new Error('PDF parsing failed: ' + e.message);
}
};
// DOCX text extraction function
window.extractDocxText = async function(arrayBuffer) {
try {
const zip = await JSZip.loadAsync(arrayBuffer);
const docXml = await zip.file('word/document.xml').async('string');
// Parse XML and extract text
const parser = new DOMParser();
const doc = parser.parseFromString(docXml, 'application/xml');
const textNodes = doc.getElementsByTagName('w:t');
let text = '';
for (let i = 0; i < textNodes.length; i++) {
text += textNodes[i].textContent;
}
// Add paragraph breaks
const paragraphs = doc.getElementsByTagName('w:p');
let result = '';
for (let i = 0; i < paragraphs.length; i++) {
const pTexts = paragraphs[i].getElementsByTagName('w:t');
let pText = '';
for (let j = 0; j < pTexts.length; j++) {
pText += pTexts[j].textContent;
}
if (pText.trim()) {
result += pText.trim() + '\n';
}
}
return result.trim() || text.trim();
} catch (e) {
throw new Error('DOCX parsing failed: ' + e.message);
}
};
</script>
<link data-trunk rel="css" href="assets/style.css">
<link data-trunk rel="rust" href="Cargo.toml" data-wasm-opt="z">
</head>
<body>
<noscript>Nabu requires JavaScript to run.</noscript>
</body>
</html>