1- const bookManifest = [
2- { name : "Genesis" , file : "genesis.json" } ,
3- { name : "1 Enoch" , file : "enoch.json" }
4- ] ;
5-
61let currentBook = null ;
2+ let currentChapter = null ;
3+ let bookData = null ;
74const bookCache = { } ;
85
9- // Fetch book data
10- async function loadBookData ( bookFile ) {
11- if ( ! bookCache [ bookFile ] ) {
12- const response = await fetch ( `data/books/${ bookFile } ` ) ;
13- const data = await response . json ( ) ;
14- bookCache [ bookFile ] = data ;
15- }
16- return bookCache [ bookFile ] ;
17- }
6+ // Navigation controls
7+ document . getElementById ( 'prevChapter' ) . addEventListener ( 'click' , ( ) => {
8+ const prev = parseInt ( currentChapter ) - 1 ;
9+ if ( prev >= 1 ) loadChapter ( prev . toString ( ) ) ;
10+ } ) ;
11+
12+ document . getElementById ( 'nextChapter' ) . addEventListener ( 'click' , ( ) => {
13+ const next = parseInt ( currentChapter ) + 1 ;
14+ if ( bookData [ currentBook ] [ next ] ) loadChapter ( next . toString ( ) ) ;
15+ } ) ;
1816
19- // Load chapter 1 of a book automatically
2017async function loadBook ( bookFile ) {
21- const bookData = await loadBookData ( bookFile ) ;
22- currentBook = Object . keys ( bookData ) [ 0 ] ; // e.g., "1 Enoch"
23- const firstChapter = Object . keys ( bookData [ currentBook ] ) [ 0 ] ; // Chapter 1
18+ bookData = await loadBookData ( bookFile ) ;
19+ currentBook = Object . keys ( bookData ) [ 0 ] ;
20+ currentChapter = Object . keys ( bookData [ currentBook ] ) [ 0 ] ;
2421
25- // Display verses
26- const versesDiv = document . getElementById ( 'verses' ) ;
27- versesDiv . innerHTML = `
28- <h2>${ currentBook } </h2>
29- ${ Object . entries ( bookData [ currentBook ] [ firstChapter ] )
30- . map ( ( [ verse , text ] ) => `
31- <p class="verse"><b>${ verse } :</b> ${ text } </p>
32- ` ) . join ( '' ) }
33- ` ;
22+ document . getElementById ( 'navigation' ) . style . display = 'flex' ;
23+ updateChapterNavigation ( ) ;
24+ loadChapter ( currentChapter ) ;
25+ }
26+
27+ function updateChapterNavigation ( ) {
28+ const chapters = Object . keys ( bookData [ currentBook ] ) ;
29+ const chapterNumbers = document . getElementById ( 'chapter-numbers' ) ;
30+
31+ chapterNumbers . innerHTML = chapters . map ( chapter => `
32+ <button class="chapter-btn ${ chapter === currentChapter ? 'active' : '' } "
33+ onclick="loadChapter('${ chapter } ')">
34+ ${ chapter }
35+ </button>
36+ ` ) . join ( '' ) ;
3437}
3538
36- // Initialize book list
37- function initBooks ( ) {
38- const bookList = document . getElementById ( 'book-list' ) ;
39- bookList . innerHTML = bookManifest
40- . map ( book => `
41- <button onclick="loadBook('${ book . file } ')">
42- ${ book . name }
43- </button>
44- ` )
45- . join ( '' ) ;
39+ function loadChapter ( chapter ) {
40+ currentChapter = chapter ;
41+ const chapterContent = bookData [ currentBook ] [ chapter ] ;
42+
43+ // Update verses display
44+ document . getElementById ( 'verses' ) . innerHTML = `
45+ <h2>${ currentBook } ${ currentChapter } </h2>
46+ ${ Object . entries ( chapterContent ) . map ( ( [ verse , text ] ) => `
47+ <p><b>${ verse } :</b> ${ text } </p>
48+ ` ) . join ( '' ) }
49+ ` ;
50+
51+ // Update chapter navigation
52+ updateChapterNavigation ( ) ;
4653}
4754
48- // Start
49- initBooks ( ) ;
55+ // Rest of the script remains the same until the init function
56+ // (Previous loadBookData and initBooks functions stay unchanged)
0 commit comments