-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
141 lines (118 loc) · 5.7 KB
/
scripts.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
/* --- Quiz Variables --- */
var level = 0;
var masterVerse = [];
var targetWord = masterVerse[level];
var wrongWords = [];
/* --- Interface --- */
function bibleApiTest() {
var searchVerse = document.getElementById("myTextArea").value;
searchVerse = searchVerse.replace(" ", "%20");
searchVerse = searchVerse.replace(":", "%3A");
var data = JSON.stringify(false);
var xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
const {data} = JSON.parse(this.responseText);
showSearch(data.passages[0].id);
//pickVerse(data.content + data.reference);//
}
});
xhr.open("GET", "https://api.scripture.api.bible/v1/bibles/9879dbb7cfe39e4d-01/search?query=" + searchVerse);
xhr.setRequestHeader('api-key', apiKey);
xhr.send(data);
}
function showSearch(i) {
var data = JSON.stringify(false);
var xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
const {data} = JSON.parse(this.responseText);
pickVerse(data.content + " " + data.reference);
}
});
xhr.open("GET", "https://api.scripture.api.bible/v1/bibles/9879dbb7cfe39e4d-01/verses/" + i + "?content-type=text&include-verse-spans=false");
xhr.setRequestHeader('api-key', apiKey);
xhr.send(data);
}
function pickVerse(i) { // Once the user selects a verse, this function hides the verse option screen, turns the verse into an array, and sends the array to the display function. //
enteredVerse = i;
masterVerse = enteredVerse.split(" "); // Global Variables //
displayVerse = masterVerse;
document.getElementById("versePick").style.display = "none";
buildPracticeDisplayVerse(displayVerse);
}
function versify() {
let enteredVerse = document.getElementById("myTextArea").value;
masterVerse = enteredVerse.split(" "); // Global Variables //
displayVerse = masterVerse;
document.getElementById("versePick").style.display = "none";
buildPracticeDisplayVerse(displayVerse);
}
function showPicker() { //Redisplays the verse options //
document.getElementById("versePick").style.display = "block";
}
function modeToggle() { // Toggle between practice and quiz //
var btn = document.getElementById("modeToggleBtn");
if (btn.innerHTML == "Start Quiz") {
btn.innerHTML = "Back to Practice";
}
else {
btn.innerHTML = "Start Quiz";
}
}
/* --- End Interface --- */
/* --- Practice --- */
function buildPracticeDisplayVerse(array) { /* Show the entire verse to the user */
var disp = document.getElementById("displayVerse");
disp.innerHTML = "";
for (var i = 0; i < array.length; i++) {
var word = array[i];
array[i] = "<span id='dispWord" + i + "' onclick='blackOut(this.id)'" + " style='border: 1px solid white; border-radius: 4px;';>" + word + "</span>";
}
disp.innerHTML = "";
disp.innerHTML = array.join(" ");
}
function blackOut(id) {
if (document.getElementById(id).style.color !== "white") {
document.getElementById(id).style.color = "white";
document.getElementById(id).style.background = "white";
document.getElementById(id).style.border = "1px solid black";
document.getElementById(id).style.boxShadow = "2px 1px 1px 1px gray;"
}
else {
document.getElementById(id).style.color = "black";
document.getElementById(id).style.background = "white";
document.getElementById(id).style.border = "1px solid white";
document.getElementById(id).style.boxShadow = "none";
}
}
function showAll() {
var words = document.getElementsByTagName("span");
for (var i = 0; i < masterVerse.length; i++) {
words[i].style.background = "white";
words[i].style.color = "black";
words[i].style.border = "1px solid white";
}
}
function blackOutAll() {
var words = document.getElementsByTagName("span");
for (var i = 0; i < masterVerse.length; i++) {
words[i].style.background = "none";
words[i].style.color = "white";
words[i].style.border = "1px solid black";
}
}
/* --- End Practice --- */
/* --- Quiz --- */
function checkAnswer(x) { /* Check answer */
var response = document.getElementById(x).innerHTML;
if (response == targetWord) {
document.getElementById("feedback").innerHTML = "You're right!";
}
else {
document.getElementById("feedback").innerHTML = "Try again.";
}
}
/* --- End Quiz --- */