Spaces:
Running
Running
Update reader.html
Browse files- reader.html +70 -33
reader.html
CHANGED
@@ -130,42 +130,79 @@
|
|
130 |
|
131 |
<script>
|
132 |
const TOTAL_PAGES = 92;
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
const updatePage = () => {
|
141 |
-
imageElement.src = `pages/${currentPage}.jpg`;
|
142 |
-
imageElement.alt = `Pagina ${currentPage}`;
|
143 |
-
prevButton.disabled = currentPage === 1;
|
144 |
-
nextButton.disabled = currentPage === TOTAL_PAGES;
|
145 |
-
const pageNumber = currentPage * 2 + 1;
|
146 |
-
pageNumberElement.textContent = `${pageNumber - 1}-${pageNumber}`;
|
147 |
-
imageElement.style.display = 'none';
|
148 |
-
loadingMessage.style.display = 'block';
|
149 |
-
};
|
150 |
|
151 |
-
|
152 |
-
|
153 |
-
loadingMessage.style.display = 'none';
|
154 |
-
};
|
155 |
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
-
nextButton.addEventListener('click', () => {
|
164 |
-
if (currentPage < TOTAL_PAGES) {
|
165 |
-
currentPage++;
|
166 |
-
updatePage();
|
167 |
-
}
|
168 |
-
});
|
169 |
|
170 |
let scale = 1;
|
171 |
const zoomStep = 0.1;
|
|
|
130 |
|
131 |
<script>
|
132 |
const TOTAL_PAGES = 92;
|
133 |
+
let currentPage = 1;
|
134 |
+
const imageElement = document.getElementById('page-image');
|
135 |
+
const prevButton = document.getElementById('prev-button');
|
136 |
+
const nextButton = document.getElementById('next-button');
|
137 |
+
const pageNumberElement = document.getElementById('page-number');
|
138 |
+
const loadingMessage = document.getElementById('loading-message');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
|
140 |
+
// Array to store preloaded images
|
141 |
+
const preloadImages = [];
|
|
|
|
|
142 |
|
143 |
+
// Function to preload images for given page numbers
|
144 |
+
const preload = (pages) => {
|
145 |
+
pages.forEach(page => {
|
146 |
+
if (page >= 1 && page <= TOTAL_PAGES) {
|
147 |
+
const img = new Image();
|
148 |
+
img.src = `pages/${page}.jpg`;
|
149 |
+
preloadImages.push(img);
|
150 |
+
}
|
151 |
+
});
|
152 |
+
};
|
153 |
+
|
154 |
+
const updatePage = () => {
|
155 |
+
// Unload images that are no longer needed
|
156 |
+
const currentPages = [currentPage - 2, currentPage - 1, currentPage, currentPage + 1, currentPage + 2];
|
157 |
+
preloadImages.forEach((img, index) => {
|
158 |
+
const page = img.src.split('/').pop().split('.')[0];
|
159 |
+
if (!currentPages.includes(page)) {
|
160 |
+
preloadImages.splice(index, 1);
|
161 |
+
}
|
162 |
+
});
|
163 |
+
|
164 |
+
imageElement.src = `pages/${currentPage}.jpg`;
|
165 |
+
imageElement.alt = `Pagina ${currentPage}`;
|
166 |
+
prevButton.disabled = currentPage === 1;
|
167 |
+
nextButton.disabled = currentPage === TOTAL_PAGES;
|
168 |
+
const pageNumber = currentPage * 2 + 1;
|
169 |
+
pageNumberElement.textContent = `${pageNumber - 1}-${pageNumber}`;
|
170 |
+
imageElement.style.display = 'none';
|
171 |
+
loadingMessage.style.display = 'block';
|
172 |
+
|
173 |
+
// Preload next and previous 2 pages
|
174 |
+
const pagesToPreload = [
|
175 |
+
currentPage - 1, currentPage, currentPage + 1,
|
176 |
+
currentPage + 2, currentPage + 3,
|
177 |
+
currentPage - 2, currentPage - 3
|
178 |
+
];
|
179 |
+
const uniquePages = pagesToPreload
|
180 |
+
.filter(page => page >= 1 && page <= TOTAL_PAGES)
|
181 |
+
.map(page => Math.floor(page))
|
182 |
+
.filter((value, index, self) => self.indexOf(value) === index);
|
183 |
+
|
184 |
+
preload(uniquePages);
|
185 |
+
};
|
186 |
+
|
187 |
+
imageElement.onload = () => {
|
188 |
+
imageElement.style.display = 'block';
|
189 |
+
loadingMessage.style.display = 'none';
|
190 |
+
};
|
191 |
+
|
192 |
+
prevButton.addEventListener('click', () => {
|
193 |
+
if (currentPage > 1) {
|
194 |
+
currentPage--;
|
195 |
+
updatePage();
|
196 |
+
}
|
197 |
+
});
|
198 |
+
|
199 |
+
nextButton.addEventListener('click', () => {
|
200 |
+
if (currentPage < TOTAL_PAGES) {
|
201 |
+
currentPage++;
|
202 |
+
updatePage();
|
203 |
+
}
|
204 |
+
});
|
205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
|
207 |
let scale = 1;
|
208 |
const zoomStep = 0.1;
|