PageSourceSearch

https://seph-efd35.web.app/sepharia.js

js seph-efd35.web.app collected 2026-10-03 12:35:18 UTC 15,275 bytes, 471 lines download raw bytes

1var qSpace = document.getElementById('questionMenu')
2
3var philM = document.getElementById('philM')//.child('topMenu')//.child('philM')
4var issM = document.getElementById('issuesM')
5var morM = document.getElementById('moralM')
6var lawM = document.getElementById('lawM')
7
8var topMenu = [philM,issM,morM,lawM]
9
10var activeM = 0;
11var activeQ = 0;
12
13var pqRef =firebase.database().ref('PhilQs/')
14var iqRef =firebase.database().ref('IssQs/')
15var mqRef =firebase.database().ref('MorQs/')
16var lqRef =firebase.database().ref('LawQs/')
17
18var refQList = [pqRef,iqRef,mqRef,lqRef]
19
20var paRef =firebase.database().ref('PhilAs/')
21var iaRef =firebase.database().ref('IssAs/')
22var maRef =firebase.database().ref('MorAs/')
23var laRef =firebase.database().ref('LawAs/')
24
25var refAList = [paRef,iaRef,maRef,laRef]
26
27var philList = [];
28var issList = [];
29var morList = [];
30var lawList = [];
31
32var masterQlist = [philList,issList,morList,lawList]
33var masterKeyList = [[],[],[],[]]
34var actQList = masterQlist[activeM]
35var actKeyList = masterKeyList[activeM]
36
37const qColor = "#3f595c";
38const selQColor = "#618c91";
39
40refQList.forEach(function(item,i){
41    item.once('value', function(snapshot){
42        masterQlist[i] = []
43        snapshot.forEach(function(childSnapshot) {
44            masterQlist[i].push(childSnapshot.val());
45            masterKeyList[i].push(childSnapshot.key);
46            console.log('q:key',childSnapshot.val()+':'+childSnapshot.key);
47        })
48    updateQs()
49    changeAnswers(activeQ)
50    document.getElementById('questionMenu').firstChild.style.backgroundColor = qColor;
51    document.getElementById('questionMenu').firstChild.style.color = "white";
52    })
53
54})
55
56topMenu.forEach(function(item,i){
57    $(item).hover(function(){
58        if (activeM != i){
59            item.style.backgroundColor = "#abc4c7"
60        }
61    },
62    function(){
63        if (activeM == i){
64            //alert(activeM + i)
65            item.style.backgroundColor = selQColor;
66        }else{
67            item.style.backgroundColor = "LightGray";
68        }
69    });
70    /*item.onmouseout = function(){
71        item.style.backgroundColor = selQColor;
72    }*/
73    item.onclick = function(){
74        changeActiveM(i)
75        changeActiveQ(0)
76    }
77})
78
79function updateQs(){
80    actQList = masterQlist[activeM]
81    actKeyList = masterKeyList[activeM]
82    var qBlock = ""
83    actQList.forEach(function(item,i){
84        let stItem = item.replace(/\s+/g, '')
85        //console.log(item,stItem);
86        qBlock += "<div id = "+stItem+">"+item+"</div>"
87    })
88    qSpace.innerHTML = qBlock;
89    checkQclicks(actQList)
90}
91
92function checkQclicks(l){
93    l.forEach(function(item,i){
94        //console.log(item)
95        let stripItem = item.replace(/\s+/g, '')
96        let wanted = document.getElementById(stripItem)
97        wanted.onclick = function(){changeActiveQ(i)}
98    })
99}
100
101function changeActiveM(selector){
102    //console.log("Selector:",selector)
103    activeM = selector;
104    activeQ = 0;
105    topMenu.forEach(function(item,i){
106        if (i == activeM){
107            item.style.backgroundColor = selQColor;
108        }else{
109            item.style.backgroundColor = "LightGray"
110        }
111    })
112    document.getElementById("addQ").innerText = "New "+topMenu[selector].innerText+" Question"
113    updateQs()
114}
115
116function changeActiveQ(ind){
117    let strip = actQList[activeQ].replace(/\s+/g, '')
118    document.getElementById(strip).style.color = "black";
119    document.getElementById(strip).style.backgroundColor = selQColor;
120    let strip2 = actQList[ind].replace(/\s+/g, '')
121    console.log('strip2',strip2)
122    document.getElementById(strip2).style.backgroundColor = qColor;
123    document.getElementById(strip2).style.color = "white";
124    document.getElementById('qSelected').innerText = document.getElementById(strip2).innerText;
125    activeQ = ind;
126    changeAnswers(activeQ)
127}
128
129function changeAnswers(qIndex){
130    let qKey = masterKeyList[activeM][qIndex]
131    refAList[activeM].child(qKey).once('value',function(snapshot){
132        //console.log('key',snapshot.key)
133        let totInfo = ''
134        snapshot.forEach(function(a){
135            let aInfo = '<div class = aBox>'
136            let cit, des, ansRef
137            a.forEach(function(inf){
138                //console.log('type',inf.key);
139                if (inf.key == 'ansRef'){
140                    ansRef = inf.val()
141                    aInfo += '<div class = ansRef><b>'+ansRef+'</b></div>'
142                    //console.log('cit: ',cit);
143                }else if(inf.key == 'cit'){
144                    cit = inf.val()
145                    aInfo += '<div class = infoBox>'+cit+'</div>'
146                    //console.log('des: ',des);
147                }else{
148                    des = inf.val()
149                    aInfo += '<b>Explanation</b><div class = infoBox>'+des+'</div></div>'
150                }
151            });
152            totInfo += aInfo;
153        })
154        //console.log('total',totInfo);
155        document.getElementById('belowButton').innerHTML = totInfo
156    })
157}
158
159function filt() {
160  // Declare variables
161  var input, filter, txtValue;
162  input = document.getElementById('myInput');
163  filter = input.value.toUpperCase();
164  actQList.forEach(function(item,i){
165      let txt = item.toUpperCase();
166      if (txt.indexOf(filter)> -1){
167          let id = item.replace(/\s+/g, '')
168          document.getElementById(id).style.display = ""
169      }else{
170          let id = item.replace(/\s+/g, '')
171          document.getElementById(id).style.display = "none"
172      }
173  })
174}
175
176var qButton = document.getElementById('addQ');
177var qInput = document.getElementById('qAdder')
178
179qButton.onclick = function(){
180    qButton.style.display = "none";
181    qInput.style.display = "block";
182    qInput.focus();
183    qInput.addEventListener("keyup", function(event) {
184      // Number 13 is the "Enter" key on the keyboard
185      if (event.keyCode === 13) {
186        // Cancel the default action, if needed
187            event.preventDefault();
188            if (qInput.value != ''){
189                let key = refQList[activeM].push(qInput.value).key;
190                console.log('key',key);
191                masterKeyList[activeM].push(key);
192                masterQlist[activeM].push(qInput.value)
193                updateQs()
194                changeAnswers(activeQ)
195                qInput.value = '';
196                qButton.style.display = "block";
197                qInput.style.display = "none";
198                changeActiveQ(masterQlist[activeM].length - 1)
199            }
200       }else if (event.keyCode === 27) {//escape
201           event.preventDefault();
202           qButton.style.display = "block";
203           qInput.style.display = "none";
204           qInput.value = '';
205       }
206    })
207}
208
209var quoteArea = document.getElementById('quoteArea');
210var quoteSpace = document.getElementById('quoteSpace');
211
212/*var titles = [];
213$.get("https://www.sefaria.org/api/index/",
214    function(data, status){
215        if (status == 'success') {
216            console.log(data);
217            c1 = []
218            data.forEach(function(item,i){
219                c1.push(item.contents);
220            });
221            findTitles(c1)
222            autoC()
223        }
224    }
225)
226
227
228function autoC(){
229    $('#text').autocomplete({
230        source:titles
231    });
232}
233
234function findTitles(clist){
235    if (clist.length == 0){return;}
236    m = [];
237    c = [];
238    t = [];
239    clist.forEach(function(item,i){
240        console.log(typeof(item))
241        item.forEach(function(it,j){m.push(it)})
242    })
243    m.forEach(function(item,i){
244        if (item.contents){
245            c.push(item.contents);
246        }else{
247            t.push(item.title)
248        }
249    })
250    titles += t;
251    console.log(titles);
252    findTitles(c)
253}
254*/
255
256/*            let c1list = [];
257            let c2list = [];
258            let c3list = [];
259            let merge1list = [];
260            let merge2list = [];
261            let titles = [];
262            data.forEach(function(item,i){
263                c1list.push(item.contents);
264            });
265            console.log(c1list);
266            c1list.forEach(function(item,i){
267                item.forEach(function(it,j){merge1list.push(it)});
268            });
269            console.log(merge1list);
270            merge1list.forEach(function(item,i){
271                if (item.contents){
272                    c2list.push(item.contents);
273                }else{
274                    titles.push(item.title)
275                }
276            });
277            console.log(c2list);
278            c2list.forEach(function(item,i){
279                item.forEach(function(it,j){merge2list.push(it)});
280            });
281
282            console.log(merge2list);
283            merge2list.forEach(function(item,i){
284                if (item.contents){
285                    c3list.push(item.contents);
286                }else{
287                    titles.push(item.title)
288                }
289            });
290            console.log(c3list)
291            console.log('titles',titles);
292            */
293
294
295
296document.getElementById('jax').onclick = function(){
297    if ($('#text').val() != ''){
298        findSource();
299    }
300}
301
302function findSource(){
303    var srcTxt = document.getElementById('text').value;
304    srcTxt = srcTxt.trim().toLowerCase().replace(/\w\S*/g, (w) => (w.replace(/^\w/, (c) => c.toUpperCase())));//capitalize
305    srcTxt = srcTxt.replace(/ /g, "_")//replace spaces with underscores
306    srcTxt += '.'+document.getElementById('sub').value.trim()
307    srcTxt += '.'+ document.getElementById('subSub').value.trim()
308    //console.log('text',srcTxt)
309    getQuote(srcTxt)
310}
311
312function getQuote(citation){
313    let url = "https://www.sefaria.org/api/texts/"+citation+"?context=0";
314    $.get(url,function(data,status){
315        if (status == 'success' && data.text) {
316            // What do when the request is successful
317            quoteSpace.style.display = 'block';
318            quoteArea.value = '';
319            let quote = data.text
320            //console.log('quote', quote)
321            //console.log('type', typeof(quote))
322            if (typeof(quote)== 'object'){
323                //alert('true')
324                quote.forEach(function(item, i){
325                    line = removeHTMLandFootnotes(item);
326                    console.log('line',line)
327                    if (i > 1){
328                        quoteArea.value +=' '+line;
329                    }else{
330                        quoteArea.value += line;
331                    }
332                });
333            }else{
334                console.log("quote",quote)
335                console.log("q", removeHTMLandFootnotes(quote))
336                quoteArea.value += removeHTMLandFootnotes(quote);
337            }
338
339            quoteArea.addEventListener("keydown", function(event) {
340                event.preventDefault();
341                if (event.keyCode === 8 || event.keyCode === 46){
342                    let start = quoteArea.selectionStart;
343                    let end = quoteArea.selectionEnd;
344                    //console.log(start,end);
345                    if (start != end){
346                        let full = quoteArea.value;
347                        let left = full.slice(0,start);
348                        let right = full.slice(end);
349                        quoteArea.value = left+' . . . '+right;
350                    }
351                }
352            });
353
354        }else if (status != 'success'){
355            // What do when the request fails
356            console.log('The request failed!',status);
357            swal('Something went wrong','Try again later','error')
358        }
359        else{
360            swal("That citation isn't valid",'Check your spelling against the titles at Sefaria.org','error')
361        }
362    })
363}
364
365/**Removes anything enclosed by <..> plus all footnotes. Returns altered line */
366function removeHTMLandFootnotes(line){
367    //Remove footnotes
368    footInd = line.indexOf('<i class="footnote">')
369    while (footInd !=-1){
370        closeInd = line.indexOf("</i>", footInd)
371        line = line.slice(0,footInd) + line.slice(closeInd+4)
372        footInd = line.indexOf('<i class="footnote">',footInd)
373    }
374
375    //Remove superscripts and subscripts
376    supInd = line.indexOf('<sup>')
377    while (supInd !=-1){
378        closeInd = line.indexOf("</sup>",supInd)
379        line = line.slice(0,supInd) + line.slice(closeInd+6)
380        supInd = line.indexOf('<sup>',supInd)
381    }
382    subInd = line.indexOf('<sub>')
383    while (subInd !=-1){
384        closeInd = line.indexOf("</sub>",subInd)
385        line = line.slice(0,subInd) + line.slice(closeInd+6)
386        subInd = line.indexOf('<sub>', subInd)
387    }
388
389    //remove remaining html tags
390    openInd= line.indexOf('<');
391    while (openInd != -1){
392        closeInd = line.indexOf(">", openInd);
393        line = line.slice(0,openInd)+line.slice(closeInd+1);
394        openInd= line.indexOf('<', openInd);
395    }
396    return line
397}
398
399$('#text').keydown(function(event){
400    if (event.which == 13||event.which == 9){
401        event.preventDefault();
402        $('#sub').focus();
403    }
404})
405
406$('#sub').keydown(function(event){
407    if (event.which == 13||event.which == 9){
408        event.preventDefault();
409        $('#subSub').focus();
410    }
411})
412$('#subSub').keydown(function(event){
413    if (event.which == 13){
414        event.preventDefault();
415        $('#jax').click();
416
417    }
418})
419
420$('#addA').click(function(){
421    //console.log('click');
422    $('.newABox').show();
423    $('#addA').hide();
424    $('#text').focus()
425})
426
427$('.exit').click(function(){
428    $('.newABox').hide();
429    $('#addA').show();
430    $('#text').val('')
431    $('#sub').val('')
432    $('#subSub').val('')
433    $('#quoteArea').val('')
434    $('#descInput').val('')
435})
436
437$('.done').click(function(){
438    let currentKey = masterKeyList[activeM][activeQ]
439    let currentRef = refAList[activeM].child(currentKey)
440    let reference = $('#text').val().trim().toLowerCase().replace(/\w\S*/g, (w) => (w.replace(/^\w/, (c) => c.toUpperCase()))) +' '+$('#sub').val()+':'+$('#subSub').val()
441    currentRef.push({
442        ansRef:reference,
443        cit:$('#quoteArea').val(),
444        des:$('#desc').val()
445    })
446    $('#text').val('');
447    $('#sub').val('');
448    $('#subSub').val('');
449    $('#quoteArea').val('');
450    $('#desc').val('');
451    $('.newABox').hide();
452    $('#addA').show();
453    changeAnswers(activeQ)
454})
455
456/*function getSelectionText() {
457    //https://stackoverflow.com/questions/5379120/get-the-highlighted-selected-text
458    var text = "";
459    var activeEl = document.activeElement;
460    var activeElTagName = activeEl ? activeEl.tagName.toLowerCase() : null;
461    if (
462      (activeElTagName == "textarea") || (activeElTagName == "input" &&
463      /^(?:text|search|password|tel|url)$/i.test(activeEl.type)) &&
464      (typeof activeEl.selectionStart == "number")
465    ) {
466        text = activeEl.value.slice(activeEl.selectionStart, activeEl.selectionEnd);
467    } else if (window.getSelection) {
468        text = window.getSelection().toString();
469    }
470    return text;
471}*/

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.