-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
279 lines (243 loc) · 9.75 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Word Flasher</title>
<style>
body {
margin: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #f0f0f0;
}
.flash {
position: absolute;
font-size: 32pt;
opacity: 0;
}
#overlay {
position: fixed;
top: 0;
left: -300px; /* Initially hidden on the left */
width: 300px;
height: 100%;
background-color: rgba(255, 255, 255, 0.9);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
box-shadow: 3px 0 10px rgba(0, 0, 0, 0.2); /* Adjust shadow to match the new direction */
transition: left 0.3s ease; /* Sliding from the left */
z-index: 999;
}
#overlay.open {
left: 0; /* When open, it slides into view from the left */
}
#overlay form {
width: 80%;
display: flex;
flex-direction: column;
gap: 10px;
}
#cogIcon {
position: fixed;
top: 20px;
left: 20px;
width: 24px;
height: 24px;
background-color: #333; /* Square */
border-radius: 50%; /* Circle */
cursor: pointer;
z-index: 1000;
}
#controlPanel {
display: flex;
justify-content: center;
gap: 10px;
margin-top: 20px;
position: absolute;
bottom: 20px;
}
button {
padding: 10px;
font-size: 16px;
cursor: pointer;
}
#randomize {
margin: 0 10px 0 0; /* Remove default margins and add space to the right */
vertical-align: middle; /* Align checkbox with the label text */
display: inline-block; /* Ensure the checkbox remains inline */
width: auto; /* Prevent the checkbox from stretching */
}
#overlay label[for="randomize"] {
display: inline-flex;
align-items: center; /* Vertically center the checkbox and label */
justify-content: flex-start; /* Align the checkbox and label to the left */
width: auto; /* Prevent the label from taking the full width */
}
</style>
</head>
<body>
<div id="flashArea" class="flash"></div>
<div id="cogIcon"></div>
<div id="overlay">
<form id="settingsForm">
<label for="category">Category:</label>
<select id="category" name="category">
<option value="tehillim">Tehillim</option>
<option value="tehillim_shvoh">Tehillim Shvoh</option>
<option value="gemora">Gemora</option>
<!-- Add more categories as needed -->
</select>
<label for="wordBank">Word Bank:</label>
<select id="wordBank" name="wordBank">
<!-- Word bank options will be populated dynamically -->
</select>
<label for="speed">Speed (seconds):</label>
<input type="number" id="speed" name="speed" min="0.1" step="0.1" value="1">
<label for="interval">Interval (seconds):</label>
<input type="number" id="interval" name="interval" min="0.1" step="0.1" value="1">
<label for="randomize">Randomize:</label>
<input type="checkbox" id="randomize" name="randomize" checked>
<button type="submit">Apply</button>
</form>
</div>
<div id="controlPanel">
<button id="pauseButton">Pause</button>
<button id="rewindButton">Rewind</button>
</div>
<script>
const categories = {
"gemora": ["Words_1.txt"],
"tehillim": ["Words_2 Letters.txt", "Words_3 Letters.txt", "Words_3-4 Letters.txt", "Words_4 Letters.txt","Words_5 Letters.txt", "Words_6 Letters.txt","Words_7 Letters.txt","Words_8-11 Letters.txt"],
"tehillim_shvoh": ["Words_שוא-נע(א).txt", "Words_שוא-נע(ב).txt", "Words_שוא-נע(ג1).txt", "Words_שוא-נע(ג2).txt", "Words_שוא-נע(ג3).txt", "Words_שוא-נע(ג4).txt", "Words_שוא-נע(ג5).txt", "Words_שוא-נע(ד).txt", "Words_שוה-נע(ה).txt" ],
// Add more categories and their corresponding word files
};
const categoriesPath = 'categories';
let currentWordBank = [];
let wordsInterval, holdInterval;
let wordHistory = [];
let currentIndex = 0;
let isPaused = false;
async function fetchWords(file) {
try {
const response = await fetch(file);
const text = await response.text();
return text.split('\n').map(word => word.trim()).filter(word => word.length > 0);
} catch (error) {
console.error("Failed to fetch words:", error);
return [];
}
}
async function fetchAllWords(files) {
try {
const allWords = await Promise.all(files.map(file => fetchWords(file)));
return allWords.flat();
} catch (error) {
console.error("Failed to fetch all words:", error);
return [];
}
}
function populateWordBankOptions(category) {
const wordBankSelect = document.getElementById('wordBank');
wordBankSelect.innerHTML = '';
const wordBanks = categories[category];
wordBanks.forEach(file => {
const option = document.createElement('option');
option.value = `${categoriesPath}/${category}/${file}`;
option.textContent = file.replace('Words_', '').replace('.txt', '');
wordBankSelect.appendChild(option);
});
const allOption = document.createElement('option');
allOption.value = "All";
allOption.textContent = "All";
wordBankSelect.appendChild(allOption);
}
document.getElementById('category').addEventListener('change', function () {
const selectedCategory = this.value;
populateWordBankOptions(selectedCategory);
});
document.getElementById("settingsForm").addEventListener("submit", async function (event) {
event.preventDefault();
const wordBank = document.getElementById('wordBank').value;
const speed = parseFloat(document.getElementById('speed').value);
const interval = parseFloat(document.getElementById('interval').value);
const randomize = document.getElementById('randomize').checked;
if (wordBank === "All") {
const selectedCategory = document.getElementById('category').value;
const files = categories[selectedCategory].map(file => `${categoriesPath}/${selectedCategory}/${file}`);
console.log(`Fetching all words from category: ${selectedCategory}`);
currentWordBank = await fetchAllWords(files);
} else {
console.log(`Fetching words from: ${wordBank}`);
currentWordBank = await fetchWords(wordBank);
}
if (currentWordBank.length === 0) {
console.error("Word bank is empty, cannot start animation.");
return;
}
wordHistory = [];
currentIndex = 0;
isPaused = false;
flashWords(speed, interval, randomize, currentWordBank);
toggleOverlay();
});
function flashWords(speed, interval, randomize, currentWordBank) {
const area = document.getElementById("flashArea");
clearInterval(wordsInterval);
clearInterval(holdInterval);
wordsInterval = setInterval(function () {
if (currentIndex >= wordHistory.length) {
const word = randomize ?
currentWordBank[Math.floor(Math.random() * currentWordBank.length)] :
currentWordBank[currentIndex % currentWordBank.length];
wordHistory.push(word);
}
const word = wordHistory[currentIndex++];
area.textContent = word;
area.style.opacity = 1;
holdInterval = setTimeout(function () {
area.style.opacity = 0;
}, speed * 1000);
}, (interval + speed) * 1000);
}
document.getElementById("pauseButton").addEventListener("click", function () {
const speed = parseFloat(document.getElementById("speed").value);
const interval = parseFloat(document.getElementById("interval").value);
const randomize = document.getElementById("randomize").checked;
if (isPaused) {
flashWords(speed, interval, randomize, currentWordBank);
document.getElementById("pauseButton").textContent = "Pause";
isPaused = false;
} else {
clearInterval(wordsInterval);
clearInterval(holdInterval);
document.getElementById("pauseButton").textContent = "Resume";
isPaused = true;
}
});
document.getElementById("rewindButton").addEventListener("click", function () {
if (currentIndex > 1) {
currentIndex -= 1;
} else if (currentIndex === 1) {
currentIndex = 0;
}
if (isPaused) {
const area = document.getElementById("flashArea");
area.textContent = wordHistory[currentIndex];
area.style.opacity = 1;
}
});
function toggleOverlay() {
const overlay = document.getElementById("overlay");
overlay.classList.toggle("open");
}
document.getElementById("cogIcon").addEventListener("click", toggleOverlay);
// Trigger initial category change to populate word bank options
document.getElementById('category').dispatchEvent(new Event('change'));
</script>
</body>
</html>