(() => { const match = location.pathname.match(/series-([a-z0-9-]+)\.html$/); if (!match) return; const list = document.querySelector('.detail-chapters'); if (!list) return; list.setAttribute('aria-busy', 'true'); fetch('manga/library.json', { cache: 'no-store' }).then(response => { if (!response.ok) throw new Error('library'); return response.json(); }).then(library => { const manga = library.series.find(item => item.id === match[1]); if (!manga) return; list.replaceChildren(); manga.chapters.forEach(chapter => { const row = document.createElement('li'); const info = document.createElement('div'); const label = document.createElement('span'); label.className = 'eyebrow'; label.textContent = 'MANGABOM'; const heading = document.createElement('h3'); heading.textContent = chapter.title; info.append(label, heading); const state = document.createElement('span'); state.className = 'chapter-state'; state.textContent = chapter.ready ? chapter.pages.length + ' страниц' : 'Скоро'; const link = document.createElement('a'); link.className = 'outline-button'; link.href = 'reader.html?series=' + encodeURIComponent(manga.id) + '&chapter=' + encodeURIComponent(chapter.id); link.textContent = chapter.ready ? 'Читать ↗' : 'Открыть ↗'; row.append(info, state, link); list.append(row); }); }).catch(() => { const notice = document.createElement('p'); notice.className = 'notice'; notice.textContent = 'Не удалось обновить список глав. Попробуй обновить страницу.'; list.before(notice); }).finally(() => list.setAttribute('aria-busy', 'false')); })();