diff --git a/alacarte-novel-website/js/app.js b/alacarte-novel-website/js/app.js index 58b5336..639c9ca 100644 --- a/alacarte-novel-website/js/app.js +++ b/alacarte-novel-website/js/app.js @@ -8,13 +8,27 @@ async function loadChaptersData() { if (isDataLoaded) return chaptersData; const chapters = []; - let chapterNum = 1; + const chapterIds = []; - // 循环加载章节,直到找不到文件 - while (true) { + // 先尝试加载1-200的整数章节 + for (let i = 1; i <= 200; i++) { + chapterIds.push(i); + // 检查是否有x.5章节 + chapterIds.push(i + 0.5); + } + + // 循环加载章节 + for (const chapterNum of chapterIds) { try { - // 格式化章节号(带前导零) - const chapterId = chapterNum.toString().padStart(2, '0'); + // 格式化章节号 + let chapterId; + if (Number.isInteger(chapterNum)) { + chapterId = chapterNum.toString().padStart(2, '0'); + } else { + // 小数章节如 107.5 + chapterId = chapterNum.toString(); + } + const response = await fetch(`data/chapter-${chapterId}.json`, { cache: 'no-store', headers: { @@ -23,30 +37,18 @@ async function loadChaptersData() { } }); - if (!response.ok) { - // 尝试不带前导零的格式 - const response2 = await fetch(`data/chapter-${chapterNum}.json`, { - cache: 'no-store', - headers: { - 'Cache-Control': 'no-cache', - 'Pragma': 'no-cache' - } - }); - if (!response2.ok) break; - const data = await response2.json(); - chapters.push(normalizeChapterData(data, chapterNum)); - } else { + if (response.ok) { const data = await response.json(); chapters.push(normalizeChapterData(data, chapterNum)); } - - chapterNum++; } catch (error) { - // 没有更多章节了 - break; + // 忽略错误,继续加载下一章 } } + // 按id排序 + chapters.sort((a, b) => a.id - b.id); + chaptersData = chapters; isDataLoaded = true;