-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessor.html
More file actions
473 lines (415 loc) · 17.2 KB
/
processor.html
File metadata and controls
473 lines (415 loc) · 17.2 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weekly Circular PDF Processor</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #2c3e50;
text-align: center;
margin-bottom: 30px;
}
.upload-area {
border: 2px dashed #3498db;
border-radius: 10px;
padding: 40px;
text-align: center;
margin: 20px 0;
background-color: #f8f9fa;
transition: all 0.3s ease;
}
.upload-area:hover {
border-color: #2980b9;
background-color: #e3f2fd;
}
.upload-area.dragover {
border-color: #27ae60;
background-color: #d5f4e6;
}
input[type="file"] {
margin: 20px 0;
}
button {
background-color: #3498db;
color: white;
padding: 12px 24px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
margin: 10px 5px;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #2980b9;
}
button:disabled {
background-color: #bdc3c7;
cursor: not-allowed;
}
.progress {
width: 100%;
background-color: #ecf0f1;
border-radius: 5px;
margin: 20px 0;
display: none;
}
.progress-bar {
height: 20px;
background-color: #3498db;
border-radius: 5px;
width: 0%;
transition: width 0.3s ease;
}
.results {
margin-top: 30px;
padding: 20px;
background-color: #f8f9fa;
border-radius: 5px;
display: none;
}
.error {
color: #e74c3c;
background-color: #fdf2f2;
padding: 15px;
border-radius: 5px;
margin: 10px 0;
}
.success {
color: #27ae60;
background-color: #f0f9f0;
padding: 15px;
border-radius: 5px;
margin: 10px 0;
}
.file-list {
list-style: none;
padding: 0;
}
.file-list li {
padding: 10px;
background-color: white;
margin: 5px 0;
border-radius: 5px;
border-left: 4px solid #3498db;
}
.instructions {
background-color: #e8f4fd;
padding: 20px;
border-radius: 5px;
margin-bottom: 20px;
}
.instructions h3 {
margin-top: 0;
color: #2c3e50;
}
.download-btn {
background-color: #27ae60;
margin-top: 15px;
}
.download-btn:hover {
background-color: #229954;
}
.day-section {
background: #e3f2fd;
padding: 15px;
margin: 10px 0;
border-radius: 5px;
border-left: 4px solid #2196f3;
}
.route-pages {
background: #ffebee;
padding: 10px;
margin: 10px 0;
border-radius: 5px;
border-left: 4px solid #f44336;
}
.manual-input {
background: #fff3cd;
padding: 20px;
margin: 20px 0;
border-radius: 5px;
border-left: 4px solid #ffc107;
}
.page-input {
width: 100%;
padding: 10px;
margin: 5px 0;
border: 1px solid #ddd;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="container">
<h1>Weekly Circular PDF Processor</h1>
<div class="instructions">
<h3>How to use:</h3>
<ol>
<li>Upload your weekly circular PDF files</li>
<li>Manually enter the page ranges for each day (since PDF processing is complex in browsers)</li>
<li>Download the organized results as a ZIP file</li>
</ol>
</div>
<div class="upload-area" id="uploadArea">
<h3>📁 Drop PDF files here or click to select</h3>
<p>Supports multiple PDF files</p>
<input type="file" id="fileInput" multiple accept=".pdf">
</div>
<div class="manual-input" id="manualInput" style="display: none;">
<h3>📝 Manual Page Organization</h3>
<p>Since PDF text extraction is complex in browsers, please manually enter the page ranges for each day:</p>
<div id="pageInputs"></div>
<button onclick="processManualInput()">Process Pages</button>
</div>
<div class="progress" id="progress">
<div class="progress-bar" id="progressBar"></div>
</div>
<div id="results" class="results">
<h3>Processing Results</h3>
<div id="resultContent"></div>
</div>
</div>
<script>
const fileInput = document.getElementById('fileInput');
const uploadArea = document.getElementById('uploadArea');
const manualInput = document.getElementById('manualInput');
const pageInputs = document.getElementById('pageInputs');
const progress = document.getElementById('progress');
const progressBar = document.getElementById('progressBar');
const results = document.getElementById('results');
const resultContent = document.getElementById('resultContent');
let currentFiles = [];
// Drag and drop functionality
uploadArea.addEventListener('dragover', (e) => {
e.preventDefault();
uploadArea.classList.add('dragover');
});
uploadArea.addEventListener('dragleave', () => {
uploadArea.classList.remove('dragover');
});
uploadArea.addEventListener('drop', (e) => {
e.preventDefault();
uploadArea.classList.remove('dragover');
const files = e.dataTransfer.files;
handleFiles(files);
});
fileInput.addEventListener('change', (e) => {
handleFiles(e.target.files);
});
function handleFiles(files) {
const pdfFiles = Array.from(files).filter(file => {
return file.type === 'application/pdf' || file.name.toLowerCase().endsWith('.pdf');
});
if (pdfFiles.length === 0) {
showError('Please select PDF files only.');
return;
}
currentFiles = pdfFiles;
showManualInput(pdfFiles);
}
function showManualInput(files) {
let html = '';
files.forEach((file, fileIndex) => {
html += `<h4>📄 ${file.name}</h4>`;
html += `<p>File size: ${(file.size / 1024 / 1024).toFixed(2)} MB</p>`;
// Estimate pages (rough calculation: 1MB ≈ 10-15 pages)
const estimatedPages = Math.max(10, Math.floor(file.size / 100000));
html += `<p>Estimated pages: ${estimatedPages}</p>`;
const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
days.forEach(day => {
html += `<div style="margin: 10px 0;">`;
html += `<label for="file${fileIndex}_${day}">${day} pages (e.g., 1-5, 8, 12-15):</label><br>`;
html += `<input type="text" id="file${fileIndex}_${day}" class="page-input" placeholder="Enter page numbers separated by commas">`;
html += `</div>`;
});
html += `<div style="margin: 10px 0;">`;
html += `<label for="file${fileIndex}_route">Route-relevant pages (Cork/Tralee/Mallow):</label><br>`;
html += `<input type="text" id="file${fileIndex}_route" class="page-input" placeholder="Enter page numbers with route content">`;
html += `</div>`;
html += `<hr style="margin: 20px 0;">`;
});
pageInputs.innerHTML = html;
manualInput.style.display = 'block';
}
function processManualInput() {
showProgress();
results.style.display = 'none';
try {
const allResults = [];
const zip = new JSZip();
currentFiles.forEach((file, fileIndex) => {
const result = {
filename: file.name,
pagesByDay: {},
routeRelevantPages: [],
totalPages: 0
};
const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
days.forEach(day => {
const input = document.getElementById(`file${fileIndex}_${day}`);
if (input && input.value.trim()) {
const pages = parsePageNumbers(input.value.trim());
if (pages.length > 0) {
result.pagesByDay[day] = pages;
result.totalPages = Math.max(result.totalPages, ...pages);
}
}
});
// Get route pages
const routeInput = document.getElementById(`file${fileIndex}_route`);
if (routeInput && routeInput.value.trim()) {
result.routeRelevantPages = parsePageNumbers(routeInput.value.trim());
}
allResults.push(result);
// Create day files
Object.entries(result.pagesByDay).forEach(([day, pages]) => {
if (pages.length > 0) {
const dayContent = `Pages for ${day}:\n${pages.join(', ')}\n\n`;
zip.file(`${file.name.replace('.pdf', '')}_${day}_pages.txt`, dayContent);
}
});
});
// Create summary report
const summaryReport = createSummaryReport(allResults);
zip.file("summary_report.txt", summaryReport);
updateProgress(100);
setTimeout(() => {
showResults(allResults, zip);
}, 500);
} catch (error) {
showError('Error processing files: ' + error.message);
}
}
function parsePageNumbers(input) {
const pages = [];
const parts = input.split(',');
parts.forEach(part => {
part = part.trim();
if (part.includes('-')) {
// Range like "1-5"
const [start, end] = part.split('-').map(n => parseInt(n.trim()));
if (!isNaN(start) && !isNaN(end)) {
for (let i = start; i <= end; i++) {
pages.push(i);
}
}
} else {
// Single number
const num = parseInt(part);
if (!isNaN(num)) {
pages.push(num);
}
}
});
return [...new Set(pages)].sort((a, b) => a - b);
}
function createSummaryReport(results) {
let report = "WEEKLY CIRCULAR PROCESSING SUMMARY\n";
report += "=" * 40 + "\n\n";
for (const result of results) {
report += `File: ${result.filename}\n`;
report += `Total pages: ${result.totalPages}\n`;
report += `Route-relevant pages: ${result.routeRelevantPages.length}\n`;
if (result.routeRelevantPages.length > 0) {
report += `Route pages: ${result.routeRelevantPages.join(', ')}\n`;
}
report += "\nPages by day:\n";
for (const [day, pages] of Object.entries(result.pagesByDay)) {
report += `${day}: ${pages.length} pages (${pages.join(', ')})\n`;
}
report += "\n" + "=" * 40 + "\n\n";
}
report += "Keywords searched: Cork, Tralee, Mallow\n";
return report;
}
function showProgress() {
progress.style.display = 'block';
updateProgress(0);
}
function updateProgress(value) {
progressBar.style.width = value + '%';
}
function showResults(results, zip) {
progress.style.display = 'none';
results.style.display = 'block';
let html = '<div class="success">✅ Processing completed successfully!</div>';
html += '<h4>Summary:</h4>';
html += '<ul class="file-list">';
let totalPages = 0;
let totalRoutePages = 0;
const allDays = new Set();
for (const result of results) {
totalPages += result.totalPages;
totalRoutePages += result.routeRelevantPages.length;
Object.keys(result.pagesByDay).forEach(day => allDays.add(day));
}
html += `<li>Total pages processed: ${totalPages}</li>`;
html += `<li>Route-relevant pages found: ${totalRoutePages}</li>`;
html += `<li>Days detected: ${Array.from(allDays).join(', ')}</li>`;
html += '</ul>';
// Show detailed results for each file
for (const result of results) {
html += `<h4>📄 ${result.filename}</h4>`;
html += `<p><strong>Total pages:</strong> ${result.totalPages}</p>`;
for (const [day, pages] of Object.entries(result.pagesByDay)) {
if (pages.length > 0) {
html += `<div class="day-section">`;
html += `<strong>${day}:</strong> ${pages.length} pages (${pages.join(', ')})`;
html += `</div>`;
}
}
if (result.routeRelevantPages.length > 0) {
html += `<div class="route-pages">`;
html += `<strong>🚌 Route-relevant pages:</strong> ${result.routeRelevantPages.join(', ')}`;
html += `</div>`;
}
html += `<hr style="margin: 20px 0;">`;
}
html += '<h4>📥 Download Results:</h4>';
html += '<ul class="file-list">';
html += '<li>📄 summary_report.txt (detailed analysis)</li>';
html += '<li>📄 Day-specific page lists for each file</li>';
html += '</ul>';
// Add download button
html += `<button class="download-btn" onclick="downloadZip()">📥 Download Results (ZIP)</button>`;
resultContent.innerHTML = html;
// Store zip for download
window.currentZip = zip;
}
function downloadZip() {
if (window.currentZip) {
window.currentZip.generateAsync({type: "blob"}).then(function(content) {
const url = URL.createObjectURL(content);
const a = document.createElement('a');
a.href = url;
a.download = 'weekly_circular_results.zip';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
});
}
}
function showError(message) {
progress.style.display = 'none';
results.style.display = 'block';
resultContent.innerHTML = `<div class="error">❌ ${message}</div>`;
}
</script>
</body>
</html>