Spaces:
Sleeping
Sleeping
Commit
·
72ea5a8
1
Parent(s):
396b62b
Update static/js/script.js
Browse files- static/js/script.js +0 -67
static/js/script.js
CHANGED
|
@@ -205,73 +205,6 @@ function toggleReadAloud(button, text) {
|
|
| 205 |
}
|
| 206 |
}
|
| 207 |
// Library
|
| 208 |
-
document.addEventListener("DOMContentLoaded", loadBooks);
|
| 209 |
-
|
| 210 |
-
function loadBooks() {
|
| 211 |
-
fetch('/books')
|
| 212 |
-
.then(response => response.json())
|
| 213 |
-
.then(books => {
|
| 214 |
-
let bookList = document.getElementById("bookList");
|
| 215 |
-
bookList.innerHTML = "";
|
| 216 |
-
books.forEach(book => {
|
| 217 |
-
let bookBlock = document.createElement("div");
|
| 218 |
-
bookBlock.className = "book";
|
| 219 |
-
|
| 220 |
-
bookBlock.innerHTML = `
|
| 221 |
-
<h3>${book.title}</h3>
|
| 222 |
-
<p>${book.description}</p>
|
| 223 |
-
<iframe src="/uploads/${book.file}" width="100%" height="300px"></iframe>
|
| 224 |
-
`;
|
| 225 |
-
|
| 226 |
-
bookList.appendChild(bookBlock);
|
| 227 |
-
});
|
| 228 |
-
})
|
| 229 |
-
.catch(error => console.error("Error loading books:", error));
|
| 230 |
-
}
|
| 231 |
-
|
| 232 |
-
// Admin login function
|
| 233 |
-
function loginAdmin() {
|
| 234 |
-
let username = document.getElementById("adminUser").value;
|
| 235 |
-
let password = document.getElementById("adminPass").value;
|
| 236 |
-
|
| 237 |
-
if (username === "admin" && password === "password") {
|
| 238 |
-
document.getElementById("uploadSection").style.display = "block";
|
| 239 |
-
document.getElementById("adminLogin").style.display = "none";
|
| 240 |
-
} else {
|
| 241 |
-
alert("Invalid credentials!");
|
| 242 |
-
}
|
| 243 |
-
}
|
| 244 |
-
|
| 245 |
-
// Upload function
|
| 246 |
-
function uploadBook() {
|
| 247 |
-
let title = document.getElementById("title").value;
|
| 248 |
-
let description = document.getElementById("description").value;
|
| 249 |
-
let file = document.getElementById("fileUpload").files[0];
|
| 250 |
-
|
| 251 |
-
if (!title || !description || !file) {
|
| 252 |
-
alert("Please fill all fields!");
|
| 253 |
-
return;
|
| 254 |
-
}
|
| 255 |
-
|
| 256 |
-
let formData = new FormData();
|
| 257 |
-
formData.append("title", title);
|
| 258 |
-
formData.append("description", description);
|
| 259 |
-
formData.append("file", file);
|
| 260 |
-
formData.append("adminUser", "admin");
|
| 261 |
-
formData.append("adminPass", "password");
|
| 262 |
-
|
| 263 |
-
fetch('/upload', {
|
| 264 |
-
method: 'POST',
|
| 265 |
-
body: formData
|
| 266 |
-
})
|
| 267 |
-
.then(response => response.json())
|
| 268 |
-
.then(data => {
|
| 269 |
-
alert(data.message);
|
| 270 |
-
loadBooks();
|
| 271 |
-
})
|
| 272 |
-
.catch(error => console.error("Error uploading book:", error));
|
| 273 |
-
}
|
| 274 |
-
|
| 275 |
|
| 276 |
|
| 277 |
|
|
|
|
| 205 |
}
|
| 206 |
}
|
| 207 |
// Library
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
|
| 209 |
|
| 210 |
|