bug fixes on the reader

This commit is contained in:
2025-12-31 18:25:42 +01:00
parent 1e144c4bad
commit e3c366836f
2 changed files with 75 additions and 51 deletions

View File

@@ -1,7 +1,4 @@
// reader.js refactorizado
const urlParams = new URLSearchParams(window.location.search);
const lang = urlParams.get('lang') ?? 'none';
const reader = document.getElementById('reader');
const panel = document.getElementById('settings-panel');
const overlay = document.getElementById('overlay');
@@ -14,6 +11,16 @@ const nextBtn = document.getElementById('next-chapter');
const lnSettings = document.getElementById('ln-settings');
const mangaSettings = document.getElementById('manga-settings');
const rawSource = urlParams.get('source') || 'anilist';
const sourceParts = rawSource.split('?');
const source = sourceParts[0];
let lang =
urlParams.get('lang') ??
new URLSearchParams(sourceParts[1] || '').get('lang') ??
'none';
const config = {
ln: {
fontSize: 18,
@@ -123,9 +130,6 @@ function updateSettingsVisibility() {
// === CAMBIO: Nueva función para traer la lista de capítulos y saber el orden ===
async function fetchChapterList() {
const urlParams = new URLSearchParams(window.location.search);
const source = urlParams.get('source') || 'anilist';
try {
// Reusamos el endpoint que lista capítulos
const res = await fetch(`/api/book/${bookId}/chapters?source=${source}&provider=${provider}`);
@@ -154,10 +158,6 @@ async function loadChapter() {
</div>
`;
const urlParams = new URLSearchParams(window.location.search);
let source = urlParams.get('source');
if (!source) source = 'anilist';
// === CAMBIO: Si no tenemos la lista de capítulos (y no es local), la pedimos ===
if (provider !== 'local' && chaptersList.length === 0) {
await fetchChapterList();
@@ -176,6 +176,15 @@ async function loadChapter() {
const res = await fetch(newEndpoint);
const data = await res.json();
const chapterMeta = chaptersList.find(
c => String(c.id) === String(currentChapterId)
);
if (chapterMeta) {
chapterLabel.textContent = `Chapter ${chapterMeta.number} - ${chapterMeta.title}`;
document.title = `Chapter ${chapterMeta.number} - ${chapterMeta.title}`;
}
// Lógica específica para contenido LOCAL
if (provider === 'local') {
const unitIndex = Number(currentChapterId); // En local el ID suele ser el índice
@@ -186,9 +195,6 @@ async function loadChapter() {
return;
}
chapterLabel.textContent = unit.name;
document.title = unit.name;
const manifestRes = await fetch(`/api/library/${unit.id}/manifest`);
const manifest = await manifestRes.json();
@@ -215,6 +221,8 @@ async function loadChapter() {
return;
}
}
const rawSource = urlParams.get('source') || 'anilist';
const source = rawSource.split('?')[0];
const res2 = await fetch(`/api/book/${bookId}?source=${source}`);
const data2 = await res2.json();
@@ -234,12 +242,14 @@ async function loadChapter() {
return;
}
if (data.title) {
chapterLabel.textContent = data.title;
document.title = data.title;
} else {
chapterLabel.textContent = `Chapter ${data.number ?? currentChapterId}`;
document.title = `Chapter ${data.number ?? currentChapterId}`;
if (!chapterMeta) {
if (data.title) {
chapterLabel.textContent = `Chapter ${data.number ?? ''} - ${data.title}`;
document.title = chapterLabel.textContent;
} else {
chapterLabel.textContent = `Chapter ${data.number ?? currentChapterId}`;
document.title = chapterLabel.textContent;
}
}
setupProgressTracking(data, source);
@@ -339,11 +349,9 @@ function changeChapter(newId) {
}
function updateURL(newId) {
const urlParams = new URLSearchParams(window.location.search);
const source = urlParams.get('source') ?? 'anilist';
// La URL ahora contiene el ID en lugar del número/índice
const newUrl = `/read/${provider}/${newId}/${bookId}?source=${source}&lang=${lang}`;
const newUrl =
`/read/${provider}/${newId}/${bookId}?source=${source}&lang=${lang}`;
window.history.pushState({}, '', newUrl);
}
@@ -602,8 +610,6 @@ document.querySelectorAll('[data-direction]').forEach(btn => {
// Botón "Atrás"
document.getElementById('back-btn').addEventListener('click', () => {
const urlParams = new URLSearchParams(window.location.search);
let source = urlParams.get('source')?.split('?')[0];
if (source === 'anilist' || !source) {
window.location.href = `/book/${bookId}`;