From 223d05299fba972d9b6df688361362731ca4ee56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=99=BE=E7=B1=B3?= Date: Fri, 27 Mar 2026 16:25:31 +0800 Subject: [PATCH] Update app.js: Support decimal chapters in navigation, use versioned cache --- alacarte-novel-website/js/app.js | 40 ++++++++++++-------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/alacarte-novel-website/js/app.js b/alacarte-novel-website/js/app.js index 3058804..5eff5da 100644 --- a/alacarte-novel-website/js/app.js +++ b/alacarte-novel-website/js/app.js @@ -3,6 +3,9 @@ let chaptersData = []; let isDataLoaded = false; +// 版本号,每次更新时修改 +const CACHE_VERSION = '20260327-1615'; + // 加载所有章节数据 async function loadChaptersData() { if (isDataLoaded) return chaptersData; @@ -15,23 +18,11 @@ async function loadChaptersData() { try { // 格式化章节号(带前导零) const chapterId = chapterNum.toString().padStart(2, '0'); - const response = await fetch(`data/chapter-${chapterId}.json`, { - cache: 'no-store', - headers: { - 'Cache-Control': 'no-cache', - 'Pragma': 'no-cache' - } - }); + const response = await fetch(`data/chapter-${chapterId}.json?v=${CACHE_VERSION}`); if (!response.ok) { // 尝试不带前导零的格式 - const response2 = await fetch(`data/chapter-${chapterNum}.json`, { - cache: 'no-store', - headers: { - 'Cache-Control': 'no-cache', - 'Pragma': 'no-cache' - } - }); + const response2 = await fetch(`data/chapter-${chapterNum}.json?v=${CACHE_VERSION}`); if (!response2.ok) break; const data = await response2.json(); chapters.push(normalizeChapterData(data, chapterNum)); @@ -51,13 +42,7 @@ async function loadChaptersData() { for (let i = 1; i <= chapterNum + 10; i++) { try { const decimalId = i + 0.5; - const response = await fetch(`data/chapter-${decimalId}.json`, { - cache: 'no-store', - headers: { - 'Cache-Control': 'no-cache', - 'Pragma': 'no-cache' - } - }); + const response = await fetch(`data/chapter-${decimalId}.json?v=${CACHE_VERSION}`); if (response.ok) { const data = await response.json(); @@ -435,11 +420,15 @@ function initReaderNav(currentId) { const data = window.chaptersData || chaptersData; + // 找到当前章节在数组中的索引 + const currentIndex = data.findIndex(ch => parseFloat(ch.id) === parseFloat(currentId)); + if (prevBtn) { - if (currentId > 1) { + if (currentIndex > 0) { + const prevChapter = data[currentIndex - 1]; prevBtn.disabled = false; prevBtn.onclick = () => { - window.location.href = `reader.html?id=${currentId - 1}`; + window.location.href = `reader.html?id=${prevChapter.id}`; }; } else { prevBtn.disabled = true; @@ -447,10 +436,11 @@ function initReaderNav(currentId) { } if (nextBtn) { - if (currentId < data.length) { + if (currentIndex < data.length - 1) { + const nextChapter = data[currentIndex + 1]; nextBtn.disabled = false; nextBtn.onclick = () => { - window.location.href = `reader.html?id=${currentId + 1}`; + window.location.href = `reader.html?id=${nextChapter.id}`; }; } else { nextBtn.disabled = true;