Spaces:
Sleeping
Sleeping
Update templates/compress.html
Browse files- templates/compress.html +19 -7
templates/compress.html
CHANGED
|
@@ -168,9 +168,9 @@
|
|
| 168 |
<form style="display: none;" id="uploadForm" enctype="multipart/form-data">
|
| 169 |
<label>Compression Type:</label>
|
| 170 |
<select name="preset" id="preset">
|
| 171 |
-
<option value="low">Low</option>
|
| 172 |
-
<option value="medium">Medium</option>
|
| 173 |
-
<option value="high">High</option>
|
| 174 |
<option value="custom" selected>Custom Size</option>
|
| 175 |
</select>
|
| 176 |
|
|
@@ -190,13 +190,11 @@
|
|
| 190 |
<!-- PDF.js -->
|
| 191 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.10.377/pdf.min.js"></script>
|
| 192 |
<script>
|
| 193 |
-
//const dropArea = document.getElementById("dropArea");
|
| 194 |
const fileInput = document.getElementById("fileInput");
|
| 195 |
const preview = document.getElementById("preview");
|
| 196 |
let sizeKB_temp;
|
| 197 |
|
| 198 |
-
|
| 199 |
-
//dropArea.addEventListener("click", () => fileInput.click());
|
| 200 |
dropArea.addEventListener("dragover", (e) => {
|
| 201 |
e.preventDefault();
|
| 202 |
dropArea.classList.add("dragover");
|
|
@@ -213,6 +211,20 @@
|
|
| 213 |
|
| 214 |
fileInput.addEventListener("change", () => {
|
| 215 |
if (fileInput.files.length) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
document.getElementById("uploadForm").style.display = "block";
|
| 217 |
showPreview(fileInput.files[0]);
|
| 218 |
}
|
|
@@ -281,7 +293,7 @@
|
|
| 281 |
targetInput.value = Math.ceil(temp);
|
| 282 |
break;
|
| 283 |
case "high":
|
| 284 |
-
var temp = (sizeKB_temp - (sizeKB_temp * 0.
|
| 285 |
targetInput.value = Math.ceil(temp);
|
| 286 |
break;
|
| 287 |
}
|
|
|
|
| 168 |
<form style="display: none;" id="uploadForm" enctype="multipart/form-data">
|
| 169 |
<label>Compression Type:</label>
|
| 170 |
<select name="preset" id="preset">
|
| 171 |
+
<option value="low">Low (10%) Compression</option>
|
| 172 |
+
<option value="medium">Medium (20%) Compression</option>
|
| 173 |
+
<option value="high">High (%70) Compression</option>
|
| 174 |
<option value="custom" selected>Custom Size</option>
|
| 175 |
</select>
|
| 176 |
|
|
|
|
| 190 |
<!-- PDF.js -->
|
| 191 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.10.377/pdf.min.js"></script>
|
| 192 |
<script>
|
|
|
|
| 193 |
const fileInput = document.getElementById("fileInput");
|
| 194 |
const preview = document.getElementById("preview");
|
| 195 |
let sizeKB_temp;
|
| 196 |
|
| 197 |
+
|
|
|
|
| 198 |
dropArea.addEventListener("dragover", (e) => {
|
| 199 |
e.preventDefault();
|
| 200 |
dropArea.classList.add("dragover");
|
|
|
|
| 211 |
|
| 212 |
fileInput.addEventListener("change", () => {
|
| 213 |
if (fileInput.files.length) {
|
| 214 |
+
const file = fileInput.files[0]; // ✅ correct way to get the file
|
| 215 |
+
const ext = file.name.split(".").pop().toLowerCase();
|
| 216 |
+
|
| 217 |
+
if (ext !== "pdf" || file.type !== "application/pdf") {
|
| 218 |
+
alert("❌ Only PDF files are allowed!");
|
| 219 |
+
fileInput.value = "";
|
| 220 |
+
return;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
const sizeKB = Math.round(file.size / 1024);
|
| 224 |
+
document.querySelector("#preset option[value='low']").textContent = `Low (~ ${Math.round(sizeKB-(sizeKB * 0.1))}KB)`;
|
| 225 |
+
document.querySelector("#preset option[value='medium']").textContent = `Medium (~ ${Math.round(sizeKB-(sizeKB * 0.3))}KB)`;
|
| 226 |
+
document.querySelector("#preset option[value='high']").textContent = `High (~ ${Math.round(sizeKB-(sizeKB * 0.6))}KB)`;
|
| 227 |
+
|
| 228 |
document.getElementById("uploadForm").style.display = "block";
|
| 229 |
showPreview(fileInput.files[0]);
|
| 230 |
}
|
|
|
|
| 293 |
targetInput.value = Math.ceil(temp);
|
| 294 |
break;
|
| 295 |
case "high":
|
| 296 |
+
var temp = (sizeKB_temp - (sizeKB_temp * 0.6));
|
| 297 |
targetInput.value = Math.ceil(temp);
|
| 298 |
break;
|
| 299 |
}
|