@@ -9,8 +9,6 @@ for (var i = 0; i < classes.length; i++) {
9
9
gitaObj [ classes [ i ] ] = Array . from ( { length : verses [ i ] } , ( _ , index ) => index + 1 ) ;
10
10
}
11
11
12
- console . log ( gitaObj )
13
-
14
12
window . onload = function ( ) {
15
13
var chapterSel = document . getElementById ( "chapter" ) ;
16
14
var slokaSel = document . getElementById ( "sloka" ) ;
@@ -27,7 +25,6 @@ window.onload = function () {
27
25
28
26
//display correct values
29
27
var y = gitaObj [ this . value ] ;
30
- console . log ( y )
31
28
for ( var i = 1 ; i <= y . length ; i ++ ) {
32
29
slokaSel . options [ slokaSel . options . length ] = new Option ( i , i ) ;
33
30
}
@@ -38,66 +35,82 @@ form.addEventListener('submit', event => {
38
35
event . preventDefault ( ) ;
39
36
const chapter = document . querySelector ( '#chapter' ) . value ;
40
37
const sloka = document . querySelector ( '#sloka' ) . value ;
41
- const url = `https://bhagavadgitaapi.in/slok/${ chapter } /${ sloka } ` ;
38
+ // const url = `https://bhagavadgitaapi.in/slok/${chapter}/${sloka}`;
39
+ const queryId = `BG${ chapter } .${ sloka } ` ;
42
40
43
41
44
42
// Check if data is already in local storage
45
- const storedData = localStorage . getItem ( `gita${ chapter } -${ sloka } ` ) ;
46
- if ( storedData ) {
47
- // Data is already in local storage
48
- const data = JSON . parse ( storedData ) ;
49
- const slokaText = data . slok ;
50
- const formattedSloka = slokaText . replace ( / \n / g, '<br>' ) ;
51
- const translation = data . siva . et ;
52
- slokaContainer . innerHTML = `
53
- <h2>||श्रीमद्भगवद्-गीता ${ chapter } .${ sloka } ||</h2>
54
- <h3>${ formattedSloka } </h3>
55
- <br>
56
- <p><strong>Translation:</strong> ${ translation } </p>
57
- ` ;
58
- } else {
59
- // Data is not in local storage, make API request
60
- var headers = { } ;
61
- fetch ( url ,
62
- {
63
- method : "GET" ,
64
- mode : 'cors' ,
65
- headers : {
66
- 'Access-Control-Allow-Origin' :'*'
67
- }
68
- } )
69
- . then ( response => response . json ( ) )
70
- . then ( data => {
71
- // Store data in local storage
72
- localStorage . setItem ( `gita${ chapter } -${ sloka } ` , JSON . stringify ( data ) ) ;
73
- // Use the data as needed
74
- const slokaText = data . slok ;
75
- const formattedSloka = slokaText . replace ( / \n / g, '<br>' ) ;
76
- const translation = data . siva . et ;
77
- slokaContainer . innerHTML = `
78
- <h2>||श्रीमद्भगवद्-गीता ${ chapter } .${ sloka } ||</h2>
79
- <h3>${ formattedSloka } </h3>
80
- <br>
81
- <p><strong>Translation:</strong> ${ translation } </p>
82
- ` ;
83
- } )
84
- . catch ( error => console . error ( error ) ) ;
85
- }
86
-
87
- //
88
-
89
- // fetch(url)
90
- // .then(response => response.json())
91
- // .then(data => {
92
- // const slokaText = data.slok;
93
- // const formattedSloka = slokaText.replace(/\n/g, '<br>');
94
- // const translation = data.siva.et;
95
- // slokaContainer.innerHTML = `
43
+ // const storedData = localStorage.getItem(`gita${chapter}-${sloka}`);
44
+ // if (storedData) {
45
+ // // Data is already in local storage
46
+ // const data = JSON.parse(storedData);
47
+ // const slokaText = data.slok;
48
+ // const formattedSloka = slokaText.replace(/\n/g, '<br>');
49
+ // const translation = data.siva.et;
50
+ // slokaContainer.innerHTML = `
96
51
// <h2>||श्रीमद्भगवद्-गीता ${chapter}.${sloka}||</h2>
97
52
// <h3>${formattedSloka}</h3>
98
53
// <br>
99
54
// <p><strong>Translation:</strong> ${translation}</p>
100
55
// `;
56
+ // } else {
57
+ // // Data is not in local storage, make API request
58
+ // var headers = {};
59
+ // fetch(url,
60
+ // {
61
+ // method : "GET",
62
+ // mode: 'cors',
63
+ // headers: {
64
+ // 'Access-Control-Allow-Origin':'*'
65
+ // }
101
66
// })
102
- // .catch(error => console.error(error));
67
+ // .then(response => response.json())
68
+ // .then(data => {
69
+ // // Store data in local storage
70
+ // localStorage.setItem(`gita${chapter}-${sloka}`, JSON.stringify(data));
71
+ // // Use the data as needed
72
+ // const slokaText = data.slok;
73
+ // const formattedSloka = slokaText.replace(/\n/g, '<br>');
74
+ // const translation = data.siva.et;
75
+ // slokaContainer.innerHTML = `
76
+ // <h2>||श्रीमद्भगवद्-गीता ${chapter}.${sloka}||</h2>
77
+ // <h3>${formattedSloka}</h3>
78
+ // <br>
79
+ // <p><strong>Translation:</strong> ${translation}</p>
80
+ // `;
81
+ // })
82
+ // .catch(error => console.error(error));
83
+ // }
84
+
85
+
86
+
87
+ // use the local json file
88
+
89
+ fetch ( 'shlokas_limited.json' )
90
+ . then ( response => response . json ( ) )
91
+ . then ( data => {
92
+ // Store data in local storage
93
+ // localStorage.setItem(`gita${chapter}-${sloka}`, JSON.stringify(data));
94
+
95
+ // Filter the data based on the user input
96
+ const filteredData = data . filter ( item => item . id === queryId ) ;
97
+ console . log ( filteredData [ 0 ] )
98
+
99
+
100
+ // Use the data as needed
101
+ const slokaText = filteredData [ 0 ] . slok ;
102
+ const formattedSloka = slokaText . replace ( / \n / g, '<br>' ) ;
103
+ const translation = filteredData [ 0 ] . siva . et ;
104
+ const hindi = filteredData [ 0 ] . tej . ht ;
105
+ slokaContainer . innerHTML = `
106
+ <h2>||श्रीमद्भगवद्-गीता ${ chapter } .${ sloka } ||</h2>
107
+ <h3>${ formattedSloka } </h3>
108
+ <br>
109
+ <p> ${ hindi } </p>
110
+ <br>
111
+ <p><strong>Translation:</strong> ${ translation } </p>
112
+ ` ;
113
+ } )
114
+ . catch ( error => console . error ( error ) ) ;
115
+
103
116
} ) ;
0 commit comments