Skip to content

Commit baac502

Browse files
committed
initial message
0 parents  commit baac502

13 files changed

+229
-0
lines changed

hello.html

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<link rel="stylesheet" href="./styles/style.css">
9+
<link rel="stylesheet" href="./styles/bootstrap.min.css">
10+
11+
<!-- Bootstrap CSS CDN -->
12+
<!-- <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
13+
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> -->
14+
15+
<title>Bhagawat Geeta Sloka</title>
16+
</head>
17+
18+
<body>
19+
<div class="container-fluid text-center m-2">
20+
<h2 class="p-2">Bhagavad Gita Sloka Fetcher</h2>
21+
<img src="https://bhagavadgitaapi.in/slok/krishna.png" alt="">
22+
<br>
23+
<p>Get the desired sloka from Gita </p>
24+
<form>
25+
<div class="row">
26+
<div class="col">
27+
<!-- <label class = "form-label" for="chapter">Select Chapter </label> -->
28+
<select class="form-control" id="chapter" name="chapter" required>
29+
<option value="" selected="selected">Select a Chapter</option>
30+
</select>
31+
</div>
32+
<div class="col">
33+
<!-- <label class = "form-label" for="sloka">Select Sloka</label> -->
34+
<select class="form-control" id="sloka" min="1" required>
35+
<option value="" selected="selected">Select a Sloka</option>
36+
</select>
37+
</div>
38+
</div>
39+
<div class="pt-2 col-12 p-3">
40+
<button class="btn btn-danger" type="submit">Fetch Sloka</button>
41+
</div>
42+
43+
</form>
44+
<div class="text-center p-2 sloka-container" id="sloka-container"></div>
45+
46+
<footer class="p-2">
47+
<p>Made with 🙏 by Dhiraj Raut. <br>
48+
Fetched from <a href="https://bhagavadgitaapi.in/" target="_blank">@BhagavadGitaApi</a> </p>
49+
</footer>
50+
</div>
51+
52+
53+
<script src="script.js"></script>
54+
55+
<!-- Bootstrap Bundle with Popper -->
56+
<!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
57+
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
58+
crossorigin="anonymous"></script> -->
59+
60+
</body>
61+
62+
</html>

images/gita.png

12.4 KB
Loading

images/gitar.webp

74.7 KB
Loading

images/krishna.png

25.6 KB
Loading

images/next.png

18.8 KB
Loading

images/temple.png

28.4 KB
Loading

manifest.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name":"Geeta",
3+
"version":"0.0.1",
4+
"manifest_version":3,
5+
"description":"Geeta Sloks",
6+
"action": {
7+
"default_popup": "hello.html",
8+
"default_icon": "images/gita.png"
9+
},
10+
"icons":{
11+
"128":"images/gita.png"
12+
}
13+
}

script.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
const form = document.querySelector('form');
2+
const slokaContainer = document.querySelector('#sloka-container');
3+
4+
const classes = Array.from({ length: 18 }, (_, index) => index + 1);
5+
const verses = [47, 72, 43, 42, 29, 47, 30, 28, 34, 42, 55, 20, 34, 27, 20, 24, 28, 78];
6+
var gitaObj = {}
7+
8+
for (var i = 0; i < classes.length; i++) {
9+
gitaObj[classes[i]] = Array.from({ length: verses[i] }, (_, index) => index + 1);
10+
}
11+
12+
console.log(gitaObj)
13+
14+
window.onload = function () {
15+
var chapterSel = document.getElementById("chapter");
16+
var slokaSel = document.getElementById("sloka");
17+
18+
for (var x in gitaObj) {
19+
chapterSel.options[chapterSel.options.length] = new Option(x, x);
20+
}
21+
22+
chapterSel.onchange = function () {
23+
//empty sloka dropdowns
24+
slokaSel.length = 1;
25+
if (this.selectedIndex < 1)
26+
return;
27+
28+
//display correct values
29+
var y = gitaObj[this.value];
30+
console.log(y)
31+
for (var i = 1; i <= y.length; i++) {
32+
slokaSel.options[slokaSel.options.length] = new Option(i, i);
33+
}
34+
}
35+
}
36+
37+
form.addEventListener('submit', event => {
38+
event.preventDefault();
39+
const chapter = document.querySelector('#chapter').value;
40+
const sloka = document.querySelector('#sloka').value;
41+
const url = `https://bhagavadgitaapi.in/slok/${chapter}/${sloka}`;
42+
43+
44+
//tried code
45+
// Check if data is already in local storage
46+
const storedData = localStorage.getItem(`gita${chapter}-${sloka}`);
47+
if (storedData) {
48+
// Data is already in local storage
49+
const data = JSON.parse(storedData);
50+
const slokaText = data.slok;
51+
const formattedSloka = slokaText.replace(/\n/g, '<br>');
52+
const translation = data.siva.et;
53+
slokaContainer.innerHTML = `
54+
<h2>||श्रीमद्‍भगवद्‍-गीता ${chapter}.${sloka}||</h2>
55+
<h3>${formattedSloka}</h3>
56+
<br>
57+
<p><strong>Translation:</strong> ${translation}</p>
58+
`;
59+
} else {
60+
// Data is not in local storage, make API request
61+
fetch(url)
62+
.then(response => response.json())
63+
.then(data => {
64+
// Store data in local storage
65+
localStorage.setItem(`gita${chapter}-${sloka}`, JSON.stringify(data));
66+
// Use the data as needed
67+
const slokaText = data.slok;
68+
const formattedSloka = slokaText.replace(/\n/g, '<br>');
69+
const translation = data.siva.et;
70+
slokaContainer.innerHTML = `
71+
<h2>||श्रीमद्‍भगवद्‍-गीता ${chapter}.${sloka}||</h2>
72+
<h3>${formattedSloka}</h3>
73+
<br>
74+
<p><strong>Translation:</strong> ${translation}</p>
75+
`;
76+
})
77+
.catch(error => console.error(error));
78+
}
79+
80+
//
81+
82+
// fetch(url)
83+
// .then(response => response.json())
84+
// .then(data => {
85+
// const slokaText = data.slok;
86+
// const formattedSloka = slokaText.replace(/\n/g, '<br>');
87+
// const translation = data.siva.et;
88+
// slokaContainer.innerHTML = `
89+
// <h2>||श्रीमद्‍भगवद्‍-गीता ${chapter}.${sloka}||</h2>
90+
// <h3>${formattedSloka}</h3>
91+
// <br>
92+
// <p><strong>Translation:</strong> ${translation}</p>
93+
// `;
94+
// })
95+
// .catch(error => console.error(error));
96+
});

styles/bootstrap.css.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

styles/bootstrap.min.css

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)