added book entries from extensions
This commit is contained in:
@@ -3,12 +3,28 @@ let allChapters = [];
|
||||
let filteredChapters = [];
|
||||
let currentPage = 1;
|
||||
const itemsPerPage = 12;
|
||||
let extensionName = null;
|
||||
|
||||
async function init() {
|
||||
try {
|
||||
const res = await fetch(`/api/book/${bookId}`);
|
||||
const path = window.location.pathname;
|
||||
const parts = path.split("/").filter(Boolean);
|
||||
let bookId;
|
||||
|
||||
if (parts.length === 3) {
|
||||
extensionName = parts[1];
|
||||
bookId = parts[2];
|
||||
} else {
|
||||
bookId = parts[1];
|
||||
}
|
||||
|
||||
const fetchUrl = extensionName
|
||||
? `/api/book/${bookId.slice(0,40)}?ext=${extensionName}`
|
||||
: `/api/book/${bookId}`;
|
||||
|
||||
const res = await fetch(fetchUrl);
|
||||
const data = await res.json();
|
||||
console.log(data)
|
||||
console.log(data);
|
||||
|
||||
if (data.error) {
|
||||
const titleEl = document.getElementById('title');
|
||||
@@ -22,6 +38,14 @@ async function init() {
|
||||
const titleEl = document.getElementById('title');
|
||||
if (titleEl) titleEl.innerText = title;
|
||||
|
||||
const extensionPill = document.getElementById('extension-pill');
|
||||
if (extensionName && extensionPill) {
|
||||
extensionPill.textContent = `${extensionName.charAt(0).toUpperCase() + extensionName.slice(1).toLowerCase()}`;
|
||||
extensionPill.style.display = 'inline-flex';
|
||||
} else if (extensionPill) {
|
||||
extensionPill.style.display = 'none';
|
||||
}
|
||||
|
||||
const descEl = document.getElementById('description');
|
||||
if (descEl) descEl.innerHTML = data.description || "No description available.";
|
||||
|
||||
@@ -76,7 +100,12 @@ async function loadChapters() {
|
||||
tbody.innerHTML = '<tr><td colspan="4" style="text-align:center; padding: 2rem;">Searching extensions for chapters...</td></tr>';
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/book/${bookId}/chapters`);
|
||||
const fetchUrl = extensionName
|
||||
? `/api/book/${bookId.slice(0, 40)}/chapters`
|
||||
: `/api/book/${bookId}/chapters`;
|
||||
|
||||
console.log(fetchUrl)
|
||||
const res = await fetch(fetchUrl);
|
||||
const data = await res.json();
|
||||
|
||||
allChapters = data.chapters || [];
|
||||
@@ -202,7 +231,7 @@ function updatePagination() {
|
||||
function openReader(bookId, chapterId, provider) {
|
||||
const c = encodeURIComponent(chapterId);
|
||||
const p = encodeURIComponent(provider);
|
||||
window.location.href = `/read/${bookId}/${c}/${p}`;
|
||||
window.location.href = `/read/${p}/${c}/${bookId}`;
|
||||
}
|
||||
|
||||
init();
|
||||
Reference in New Issue
Block a user