Restore original app.js

This commit is contained in:
小虾米 2026-03-27 16:14:34 +08:00
parent a0b3188994
commit 190edb9003

View File

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