-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
119 lines (103 loc) · 4.13 KB
/
index.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
<html>
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Q4JTMRC626"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-Q4JTMRC626');
</script>
<title>bible regex</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<style>
.title {
text-align: center;
}
body {
text-align: center;
font-size: 18px;
width: 60%;
margin: 0 auto;
}
</style>
</head>
<body>
<header>
<h1 class="title">חיפוש בתנ"ך</h1>
</header>
<form id="myform" dir="rtl">
הכניסו את מספר האותיות הרצוי
</br>
לדוגמא 3,6 - "בראשית ברא"
</br> </br>
<label for="book">בחר חומש</label>
<select name="book" id="book">
<option value="Genesis" selected="selected">בראשית</option>
<option value="Exodus">שמות</option>
<option value="Leviticus">ויקרא</option>
<option value="Numbers">במדבר</option>
<option value="Deuteronomy">דברים</option>
</select>
</br> </br> </br>
<input class="u-full-width" type="text" dir="ltr" id="user_input" />
<input value="חפש!" type="submit">
</form>
<ul><div id="res" dir="rtl" style="text-align: right"></div></ul>
<script>
function init() {
var form = document.getElementById("myform");
form.onsubmit = showRes;
function handleForm(event) {
event.preventDefault();
}
form.addEventListener("submit", handleForm);
}
window.onload = init;
function showRes(params) {
selected_book = document.getElementById("book").value;
url = "https://raw.githubusercontent.com/Sefaria/Sefaria-Export/master/json/Tanakh/Torah/"+selected_book+"/Hebrew/Tanach%20with%20Text%20Only.json";
fetch(url)
.then(response => response.json())
.then(json => showRes1(all_json = json))
}
function showRes1(all_json) {
user_input = document.getElementById(
"user_input"
).value;
if (!user_input) {
document.getElementById("res").innerHTML = "<b>אנא הכניסו מספר אותיות רצוי</b></br>";
return;
}
document.getElementById("res").innerHTML = "<h2>תוצאות:</h2>";
user_input_num = user_input.split(',').map(Number);
regex_from_user = '( |^)';
len = 0;
user_input_num.forEach(element => {
len += element + 1
regex_from_user += "\\S".repeat(element) + " ";
});
regex_from_user = regex_from_user.trim(" ");
regex_from_user += '( |$)';
var sel = document.getElementById("book");
var bookname = sel.options[sel.selectedIndex].text;
var obj = all_json;
sefer = obj["text"];
(sefer).forEach(perek => {
perek.forEach(org_pasuk => {
pasuk = org_pasuk.replaceAll("־", " ");
var n = pasuk.search(new RegExp(regex_from_user));
if (n >= 0) {
var redText = pasuk.substring(n, n + len);
new_text = pasuk.substring(0, n) + "<a style='color:red;'>" + redText + "</a>" + pasuk.substring(n + len);
p = sefer.indexOf(perek) + 1;
pp = perek.indexOf(org_pasuk) + 1;
location1 = " (" + bookname + " פרק " + (p) + " פסוק " + (pp) + ")";
document.getElementById("res").innerHTML += "<li>\"" + new_text + "\"" + location1 + "</li>";
}
});
});
}
</script>
</body>
</html>