-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
142 lines (124 loc) · 5.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// example of accessing Bible text from JSON via JavaScript
import { bible } from "./bible.js"
const books = getBooks();
// MIT LICENSE
// bible.js Copyright 2023 by David Van Wagner dave@davevw.com
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation files
// (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
function getBooks() {
return bible.filter(x => x.chapter == 1 && x.verse == 1).map(x => x.book);
}
function findVerse(book, chapter, verse) {
return bible.find(x => x.book == book && x.chapter == chapter && x.verse == verse);
}
function countBooks() {
return books.length;
}
function countChapters(book) {
return bible.filter(x => x.book == book && x.verse == 1).length;
}
function countVerses(book, chapter) {
return bible.filter(x => x.book == book && x.chapter == chapter).length;
}
function findText(text) {
text = text.toLowerCase();
return bible.filter(x => x.text.toLowerCase().includes(text));
}
const diagDiv = document.getElementById('diag');
function refreshVerse() {
const textDiv = document.getElementById('text');
const book = books[document.getElementById('books').selectedIndex];
const chapter = document.getElementById('chapter').selectedIndex+1;
const verse = document.getElementById('verse').selectedIndex+1;
const match = findVerse(book, chapter, verse);
textDiv.innerHTML = `<p><b>${match.text}</b></p>`
}
function fillSelectBooks() {
const selectBooks = document.getElementById('books');
let booknum = 0
selectBooks.innerHTML = "";
books.map(book => {
selectBooks.innerHTML += `<option value="${booknum}">${book}</option>`;
booknum++;
})
}
function fillChapters() {
const selectChapter = document.getElementById('chapter');
const book = books[document.getElementById('books').selectedIndex];
selectChapter.innerHTML = "";
bible.filter(x => x.book == book && x.verse == 1).map(x => {
selectChapter.innerHTML += `<option value="${x.chapter}">${x.chapter}</option>`;
})
}
function fillVerses() {
const selectVerse = document.getElementById('verse');
const book = books[document.getElementById('books').selectedIndex];
const chapter = document.getElementById('chapter').selectedIndex+1;
selectVerse.innerHTML = "";
bible.filter(x => x.book == book && x.chapter == chapter).map(x => {
selectVerse.innerHTML += `<option value="${x.verse}">${x.verse}</option>`;
})
}
////////////////////////////////////////////////////////////////////////
fillSelectBooks();
fillChapters();
fillVerses();
refreshVerse();
document.getElementById('books').onchange = function() {
document.getElementById('chapter').selectedIndex = 0;
document.getElementById('verse').selectedIndex = 0;
fillChapters();
fillVerses();
refreshVerse();
}
document.getElementById('chapter').onchange = function() {
document.getElementById('verse').selectedIndex = 0;
fillVerses();
refreshVerse();
}
document.getElementById('verse').onchange = function() {
refreshVerse();
}
diagDiv.innerHTML += `<p>${bible.length} verses</p>`;
let bytes = 0;
bible.map(x => bytes += x.text.length+1); // add text and newline
diagDiv.innerHTML += `<p>${bytes} bytes text</p>`;
diagDiv.innerHTML += `<p>${countBooks()} books</p>`;
diagDiv.innerHTML += `<p>${countChapters("GENESIS")} chapters in Genesis</p>`;
diagDiv.innerHTML += `<p>${countVerses("GENESIS", 1)} verses in Genesis 1</p>`;
diagDiv.innerHTML += `<p>${countChapters("PSALMS")} chapters in Psalms</p>`;
diagDiv.innerHTML += `<p>${countVerses("PSALMS", 139)} verses in Psalms 139</p>`;
diagDiv.innerHTML += `<p>${countChapters("MATTHEW")} chapters in Matthew</p>`;
diagDiv.innerHTML += `<p>${countVerses("MATTHEW", 1)} verses in Matthew 1</p>`;
diagDiv.innerHTML += `<p>${countChapters("REVELATION")} chapters in Revelation</p>`;
diagDiv.innerHTML += `<p>${countVerses("REVELATION", 22)} verses in Relevation 22</p>`;
diagDiv.innerHTML += "<hr>"
const searchText = "great fish"
let count = 0;
let matches = findText(searchText)
diagDiv.innerHTML += `<p>${searchText} mentioned ${matches.length} times`
matches.map(x => {
if (++count < 100)
{
diagDiv.innerHTML += `<p>${x.book} ${x.chapter}:${x.verse}`
diagDiv.innerHTML += `<p>${x.text}</p>`
}
});