-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbible-batch-search.html
392 lines (347 loc) · 14.7 KB
/
bible-batch-search.html
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bible Verse Search</title>
<style>
#searchInput {
resize: none;
overflow-y: hidden;
width:100%;
border: none;
border-bottom: 2px solid red;
background-color: white;
background-image: url('https://www.obeyingchur.ch/content/images/2024/01/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding-left: 40px;
}
input[type=button] {
background-color: white;
color: black;
border: 1px solid #b18c30;
border-radius: 8px;
padding: 5px 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
input[type=button]:hover {
background-color: #b18c30;
color: white;
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
}
button {background-color: #b18c30;
border: none;
border-radius: 12px;
color: white;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
opacity: 0.6;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
button:hover {
background-color: #b18c30;
opacity: 1;
}
button:disabled {
pointer-events: none;
}
#resultContainer p {
display: block;
margin-top: 1em;
margin-bottom: 1em;
margin-left: 0;
margin-right: 0;
font-size: 20px;
color:rgb(60, 60, 60);
}
</style>
<script src="scripts/pdfmake.min.js"></script>
<script src="scripts/vfs_fonts.js"></script>
</head>
<body>
<h4>Click a Book to add to the Search</h4>
<div id="bookContainer"></div>
<select id="books-combo-box" style='display:none'></select>
<label for="searchInput"><h4>Enter Verses (comma-separated):</h4></label>
<textarea id="searchInput" oninput="autoResize(this)" placeholder="യോഹന്നാൻ 3:16, Ps 1, യോശുവ 1:7-8, mat 5"></textarea>
<div class="button-container">
<button onclick="searchVerses()">Search</button>
<button onclick="exportVersesToPDF()" id='exportToPDFBtn' disabled>Export Verses</button>
<button onclick="copyVersesToClipboard()" id='copyToClipboardBtn' disabled>Copy Verses to Clipboard</button>
<button onclick="document.getElementById('searchInput').value='';autoResize(document.getElementById('searchInput'));">Clear Search</button>
<button onclick="clearVerses()">Clear Verses</button>
<button onclick="location.reload()">Refresh</button>
</div>
<div id="resultContainer"></div>
<textarea id="versesTextArea" style='display:none'></textarea>
<script>
let bibleData;
const malyalamBibleBooks = [
"ഉല്പത്തി", "പുറപ്പാട്", "ലേവ്യപുസ്തകം", "സംഖ്യാപുസ്തകം", "ആവർത്തനം", "യോശുവ", "ന്യായാധിപന്മാർ",
"രൂത്ത്", "1 ശമൂവേൽ", "2 ശമൂവേൽ", "1 രാജാക്കന്മാർ", "2 രാജാക്കന്മാർ", "1 ദിനവൃത്താന്തം",
"2 ദിനവൃത്താന്തം", "എസ്രാ", "നെഹെമ്യാവു", "എസ്ഥേർ", "ഇയ്യോബ്", "സങ്കീർത്തനങ്ങൾ",
"സദൃശ്യവാക്യങ്ങൾ", "സഭാപ്രസംഗി", "ഉത്തമഗീതം", "യെശയ്യാ", "യിരമ്യാവു", "വിലാപങ്ങൾ",
"യെഹേസ്കേൽ", "ദാനീയേൽ", "ഹോശേയ", "യോവേൽ", "ആമോസ്", "ഓബദ്യാവു", "യോനാ",
"മീഖാ", "നഹൂം", "ഹബക്കൂക്ക്", "സെഫന്യാവു", "ഹഗ്ഗായി", "സെഖര്യാവു", "മലാഖി", "മത്തായി",
"മർക്കൊസ്", "ലൂക്കോസ്", "യോഹന്നാൻ", "പ്രവൃത്തികൾ", "റോമർ", "1 കൊരിന്ത്യർ", "2 കൊരിന്ത്യർ",
"ഗലാത്യർ", "എഫെസ്യർ", "ഫിലിപ്പിയർ", "കൊലൊസ്സ്യർ", "1 തെസ്സലൊനീക്യർ", "2 തെസ്സലൊനീക്യർ",
"1 തിമൊഥെയൊസ്", "2 തിമൊഥെയൊസ്", "തീത്തൊസ്", "ഫിലേമോൻ", "എബ്രായർ", "യാക്കോബ്",
"1 പത്രൊസ്", "2 പത്രൊസ്", "1 യോഹന്നാൻ", "2 യോഹന്നാൻ", "3 യോഹന്നാൻ","യൂദാ", "വെളിപ്പാട്"
];
const englishBibleBooks = [
"Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy", "Joshua",
"Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings", "1 Chronicles",
"2 Chronicles", "Ezra", "Nehemiah", "Esther", "Job", "Psalms", "Proverbs", "Ecclesiastes",
"Song of Solomon", "Isaiah", "Jeremiah", "Lamentations", "Ezekiel", "Daniel",
"Hosea", "Joel", "Amos", "Obadiah", "Jonah", "Micah", "Nahum", "Habakkuk", "Zephaniah",
"Haggai", "Zechariah", "Malachi", "Matthew", "Mark", "Luke", "John", "Acts", "Romans",
"1 Corinthians", "2 Corinthians", "Galatians", "Ephesians", "Philippians", "Colossians",
"1 Thessalonians", "2 Thessalonians", "1 Timothy", "2 Timothy", "Titus", "Philemon",
"Hebrews", "James", "1 Peter", "2 Peter", "1 John", "2 John", "3 John", "Jude", "Revelation"
];
loadBibleData();
loadBooksComboBox();
loadBooksButtons();
autoResize(document.getElementById('searchInput'));
function loadBooksButtons() {
const bookContainer = document.getElementById('bookContainer');
// Populate buttons
malyalamBibleBooks.forEach((book, index) => {
const spanElm = document.createElement('span');
//spanElm.style.display = 'inline-block';
//spanElm.style.padding = '2px';
const inputElm = document.createElement('input');
inputElm.type = 'button';
inputElm.value = book;
inputElm.onclick = function() {
bookButtonClickHandler(this);
};
spanElm.appendChild(inputElm);
bookContainer.appendChild(spanElm);
if (index == 38) {
let brElm = document.createElement('br');
bookContainer.appendChild(brElm);
brElm = document.createElement('br');
bookContainer.appendChild(brElm);
}
});
}
function bookButtonClickHandler(buttonObj) {
const searchInputTxtArea = document.getElementById('searchInput');
let searchInputValue = searchInputTxtArea.value;
if (isLastCharacterComma(searchInputValue) || searchInputValue == '') {
searchInputTxtArea.value += (buttonObj.value + " ");
} else {
searchInputTxtArea.value += (', ' + buttonObj.value + " ");
}
document.getElementById("searchInput").focus();
autoResize(document.getElementById('searchInput'));
}
function loadBooksComboBox() {
// Get the select element
const booksComboBox = document.getElementById('books-combo-box');
// Populate the combo box with options
englishBibleBooks.forEach((book, index) => {
const option = document.createElement('option');
option.value = index;
option.text = book;
booksComboBox.appendChild(option);
});
}
function loadBibleData() {
<!-- Data Source: https://github.com/godlytalias/Bible-Database/tree/master/Malayalam -->
fetch('https://raw.githubusercontent.com/godlytalias/Bible-Database/master/Malayalam/bible.json')
.then(response => response.json())
.then(data => {
bibleData = data;
})
.catch(error => console.error('Error fetching JSON:', error));
}
function clearVerses() {
const resultContainer = document.getElementById('resultContainer');
const versesTextAreaObj = document.getElementById('versesTextArea');
resultContainer.innerHTML = '';
versesTextAreaObj.value = '';
}
function searchVerses() {
const searchInput = document.getElementById('searchInput').value;
if (searchInput === null || searchInput.length === 0) {
alert('Please provide some verses to search!');
return;
}
const resultContainer = document.getElementById('resultContainer');
const versesTextAreaObj = document.getElementById('versesTextArea');
clearVerses();
const searchInputs = searchInput.split(',');
searchInputs.forEach(searchInputVerse => {
searchInputVerse = searchInputVerse.trim();
let errorReferences = '';
try {
let searchVerseObject = parseReference(searchInputVerse);
console.log(JSON.stringify(searchVerseObject, null, 2));
const chapterObj = bibleData.Book[searchVerseObject.bookIndex].Chapter[searchVerseObject.chapterIndex];
if (searchVerseObject.verses.length > 0) {
searchVerseObject.verses.forEach(verse => {
let verseObj = chapterObj.Verse[verse.verseIndex];
resultContainer.innerHTML += `<p id="${verseObj.Verseid}">${searchVerseObject.bookName} ${searchVerseObject.chapter}:${verse.verseNo} - ${verseObj.Verse}</p>`;
versesTextAreaObj.value += `${searchVerseObject.bookName} ${searchVerseObject.chapter}:${verse.verseNo} - ${verseObj.Verse}\r\n`;
});
} else {
chapterObj.Verse.forEach((verseObj, index) => {
const verseNo = index + 1;
resultContainer.innerHTML += `<p id="${verseObj.Verseid}">${searchVerseObject.bookName} ${searchVerseObject.chapter}:${verseNo} - ${verseObj.Verse}</p>`;
versesTextAreaObj.value += `${searchVerseObject.bookName} ${searchVerseObject.chapter}:${verseNo} - ${verseObj.Verse}\r\n`;
});
}
} catch(err) {
errorReferences += ('\r\n' + searchInputVerse);
}
if (errorReferences != '') {
alert("Format of the following references (or the references) are invalid, other verses will be displayed" + errorReferences);
}
});
document.getElementById('copyToClipboardBtn').disabled = false;
document.getElementById('exportToPDFBtn').disabled = false;
}
function parseReference(reference) {
const [bookName, rest] = splitBookNameAndRest(reference);
const [chapter, versesRange] = rest.split(':');
let verses = [];
if (versesRange) {
if (versesRange.includes('-')) {
const [start, end] = versesRange.split('-');
const startVerse = parseInt(start, 10);
const endVerse = parseInt(end, 10);
for (let i = startVerse; i <= endVerse; i++) {
verses.push({verseNo: i, verseIndex: i-1});
}
} else {
verseNo = parseInt(versesRange, 10);
verses.push({verseNo: verseNo, verseIndex: verseNo-1});
}
}
const [formattedBookName, bookIndex] = getNumberFromBookName(bookName);
const result = {
bookName: formattedBookName,
bookIndex: bookIndex,
chapter: parseInt(chapter, 10),
chapterIndex: parseInt(chapter, 10)-1 ,
verses: verses
};
return result;
}
function splitBookNameAndRest(reference) {
reference = combineSpaces(reference);
// For reference with spaces in book name, example: 1 John, 2 John etc.
if (startsWithDigit(reference)) {
return splitFromSecondSpace(reference);
} else {
return reference.split(' ');
}
}
function combineSpaces(inputString) {
// Use a regular expression to replace multiple spaces with a single space
return inputString.replace(/\s+/g, ' ');
}
function getNumberFromBookName(bookName) {
let formattedBookName = bookName;
let bookIndex = malyalamBibleBooks.indexOf(bookName);
if (bookIndex == -1) {
bookIndex = englishBibleBooks.findIndex(book => book.toLowerCase().startsWith(bookName.toLowerCase()));
formattedBookName = malyalamBibleBooks[bookIndex];
}
return [formattedBookName, bookIndex];
}
function autoResize(textarea) {
textarea.style.height = 'auto';
textarea.style.height = (textarea.scrollHeight) + 'px';
}
function exportVersesToPDF() {
<!-- https://pdfmake.github.io/docs/0.1/fonts/custom-fonts-client-side/vfs/ -->
// Get the textarea element by its id
var exportDataObj = document.getElementById("versesTextArea");
// Get the data to export from the textarea
var dataToExport = exportDataObj.value;
pdfMake.fonts = {
'Nirmala UI': {
normal: 'Nirmala.ttf',
bold: 'NirmalaB.ttf',
semilight: 'NirmalaS.ttf'
},
Roboto: {
normal: 'Roboto-Regular.ttf',
bold: 'Roboto-Medium.ttf',
italics: 'Roboto-Italic.ttf',
bolditalics: 'Roboto-MediumItalic.ttf'
}
};
const lines = dataToExport.split(/\r?\n|\r|\n/g);
const lineItems = lines.flatMap((lineItem, index) => [
{
text: lineItem,
fontSize: 12
},
{ text: " ", fontSize: 12 }
]);
// Create a PDF document definition
var docDefinition = {
content: lineItems,
defaultStyle: {
font: 'Nirmala UI'
}
};
// Create a PDF using pdfmake
pdfMake.createPdf(docDefinition).download("bible-verses.pdf");
}
function copyVersesToClipboard() {
copyToClipboard('versesTextArea');
}
function copyToClipboard(textAreaId) {
/* Create textarea object which hold the text to be copied */
var dataTextArea = document.getElementById(textAreaId);
dataTextArea.style.display = 'inline';
/* Select the text in the temporary textarea */
dataTextArea.select();
dataTextArea.setSelectionRange(0, 99999); /* For mobile devices */
/* Copy the selected text to the clipboard using the Clipboard API */
document.execCommand("copy");
dataTextArea.style.display = 'none';
/* Alert the user that the text has been copied */
alert("Copied to clipboard!");
}
function isLastCharacterComma(inputString) {
// Remove trailing whitespaces
var trimmedString = inputString.trim();
// Check if the last character is a comma
return trimmedString.charAt(trimmedString.length - 1) === ',';
}
function startsWithDigit(inputString) {
return /^\d/.test(inputString);
}
function splitFromSecondSpace(inputString) {
const firstSpaceIndex = inputString.indexOf(' ');
const secondSpaceIndex = inputString.indexOf(' ', firstSpaceIndex + 1);
if (secondSpaceIndex !== -1) {
const firstPart = inputString.slice(0, secondSpaceIndex);
const secondPart = inputString.slice(secondSpaceIndex + 1);
return [firstPart, secondPart];
}
// Return the original string if there are not enough spaces
return [inputString];
}
function startsWithLetter(inputString) {
return /^[a-zA-Z]/.test(inputString);
}
</script>
</body>
</html>