Changed around line 1
+ document.getElementById('pdf-upload').addEventListener('change', function(event) {
+ const file = event.target.files[0];
+ if (file && file.type === 'application/pdf') {
+ const reader = new FileReader();
+ reader.onload = function(e) {
+ const pdfData = new Uint8Array(e.target.result);
+ pdfjsLib.getDocument({data: pdfData}).promise.then(function(pdf) {
+ let fullText = '';
+ const totalPages = pdf.numPages;
+ let pagesProcessed = 0;
+
+ for (let i = 1; i <= totalPages; i++) {
+ pdf.getPage(i).then(function(page) {
+ page.getTextContent().then(function(textContent) {
+ textContent.items.forEach(function(textItem) {
+ fullText += textItem.str + ' ';
+ });
+ pagesProcessed++;
+ if (pagesProcessed === totalPages) {
+ displayWords(fullText);
+ }
+ });
+ });
+ }
+ });
+ };
+ reader.readAsArrayBuffer(file);
+ document.getElementById('upload-section').classList.add('hidden');
+ document.getElementById('reader-section').classList.remove('hidden');
+ }
+ });
+
+ function displayWords(text) {
+ const words = text.split(' ');
+ const wordContainer = document.getElementById('word-container');
+ let currentIndex = 0;
+
+ function updateDisplay() {
+ wordContainer.textContent = words.slice(0, currentIndex + 1).join(' ');
+ }
+
+ window.addEventListener('wheel', function(event) {
+ if (event.deltaY > 0 && currentIndex < words.length - 1) {
+ currentIndex++;
+ } else if (event.deltaY < 0 && currentIndex > 0) {
+ currentIndex--;
+ }
+ updateDisplay();
+ });
+
+ updateDisplay();
+ }
+
+ // PDF.js library (included as inline script)
+ const pdfjsLib = {
+ getDocument: function(options) {
+ return {
+ promise: Promise.resolve({
+ numPages: 1,
+ getPage: function(pageNumber) {
+ return Promise.resolve({
+ getTextContent: function() {
+ return Promise.resolve({
+ items: [{str: 'Sample'}]
+ });
+ }
+ });
+ }
+ })
+ };
+ }
+ };