-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
406 lines (398 loc) · 12.5 KB
/
index.html
File metadata and controls
406 lines (398 loc) · 12.5 KB
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<!doctype html>
<html class="cursor">
<head>
<title>
Decoder
</title>
<script src="https://epicenterprograms.github.io/standards/behavior/general.js"></script>
<!--
<script src="file:///C:/Users/rtben/Documents/GitHub/standards/behavior/general.js"></script>
-->
<script>
var S = Standards.general;
var worker = new Worker("brain.js");
// https://www.worldclasslearning.com/english/five-verb-forms.html
var words = [[]]; // holds every English word in arrays in order of increasing word length
var verbs = [[]]; // holds every verb in arrays in order of increasing word length
var solutions = []; // holds all possible solutions
var filtered = {};
var hidden = [];
var solutionIndex = 0; // holds which solution is to be displayed
window.addEventListener("finished", function() {
// sets "words" to a list of English words
S.getFile("word list.txt", function (wordList) {
wordList = wordList.trim().split(/\r\n|\n/); // sets words to an array of lines of text
wordList.pop(); // For some reason, there's an empty item at the end of the list that I need to get rid of.
wordList.forEach(function (word) {
while (word.length > words.length) {
words.push([]);
}
words[word.length - 1].push(word);
});
});
// sets "verbs" to a list of verbs
S.getFile("verbs.txt", function (list) {
list.trim().split(/\r\n|\n| /).forEach(function (verb) {
while (verb.length > verbs.length) {
verbs.push([]);
}
verbs[verb.length - 1].push(verb);
});
});
// gives the decode button functionality
document.getElementById("decode").addEventListener("click", function() {
if (S.getId("code").value != "") {
var styles = document.styleSheets[1].cssRules || document.styleSheets[1].rules;
S.forEach(styles, function(style) {
if (style.selectorText == ".cursor") {
style.style.cursor = "progress";
return "break";
}
});
document.getElementById("before").style.display = "none";
document.getElementById("during").style.display = "block";
decode();
}
});
// gives the "superFastLast" button functionality
S.getId("superFastLast").addEventListener("click", function() {
if (solutionIndex > 999) {
solutionIndex -= 1000;
} else {
solutionIndex = solutions.length - 1;
}
navigate();
});
// gives the "fastLast" button functionality
S.getId("fastLast").addEventListener("click", function() {
if (solutionIndex > 49) {
solutionIndex -= 50;
} else {
solutionIndex = solutions.length - 1;
}
navigate();
});
// gives the "last" button functionality
S.getId("last").addEventListener("click", function() {
if (solutionIndex > 0) {
solutionIndex--;
} else {
solutionIndex = solutions.length - 1;
}
navigate();
});
// gives the "next" button functionality
S.getId("next").addEventListener("click", function() {
if (solutionIndex < solutions.length - 1) {
solutionIndex++;
} else {
solutionIndex = 0;
}
navigate();
});
// gives the "fastNext" button functionality
S.getId("fastNext").addEventListener("click", function() {
if (solutionIndex < solutions.length - 50) {
solutionIndex += 50;
} else {
solutionIndex = 0;
}
navigate();
});
// gives the "superFastNext" button functionality
S.getId("superFastNext").addEventListener("click", function() {
if (solutionIndex < solutions.length - 1000) {
solutionIndex += 1000;
} else {
solutionIndex = 0;
}
navigate();
});
// gives the "jump" button functionality
S.getId("jump").addEventListener("click", function() {
solutionIndex = S.getId("jumpIndex").value - 1;
S.getId("jumpIndex").value = "";
navigate();
});
// gives the findLast button functionality
S.getId("findLast").addEventListener("click", function() {
var startingIndex = solutionIndex;
var searchText = S.getId("searchText").value;
do {
if (solutionIndex > 0) {
solutionIndex--;
} else {
solutionIndex = solutions.length - 1;
}
} while (!solutions[solutionIndex].includes(searchText) && solutionIndex != startingIndex);
if (solutionIndex == startingIndex) {
alert("Your search text isn't present in any solution.");
} else {
navigate();
}
});
// gives the findNext button functionality
S.getId("findNext").addEventListener("click", function() {
var startingIndex = solutionIndex;
var searchText = S.getId("searchText").value;
do {
if (solutionIndex < solutions.length - 1) {
solutionIndex++;
} else {
solutionIndex = 0;
}
} while (!solutions[solutionIndex].includes(searchText) && solutionIndex != startingIndex);
if (solutionIndex == startingIndex) {
alert("Your search text isn't present in any solution.");
} else {
navigate();
}
});
// gives the lastWord button functionality
S.getId("lastWord").addEventListener("click", function() {
if (isNaN(S.getId("wordIndex").value) || S.getId("wordIndex").value < 1) {
S.getId("wordIndex").value = 1;
} else if (S.getId("wordIndex").value > S.getId("solution").value.split(" ").length) {
S.getId("wordIndex").value = S.getId("solution").value.split(" ").length
}
var index = Number(S.getId("wordIndex").value) - 1;
var startingIndex = solutionIndex;
var word = S.getId("solution").value.split(" ")[index];
do {
if (solutionIndex > 0) {
solutionIndex--;
} else {
solutionIndex = solutions.length - 1;
}
} while (solutions[solutionIndex].split(" ")[index] == word && solutionIndex != startingIndex);
if (solutionIndex == startingIndex) {
alert("There's only one word which fits at that place in these solutions.");
} else {
navigate();
}
});
// gives the nextWord button functionality
S.getId("nextWord").addEventListener("click", function() {
if (isNaN(S.getId("wordIndex").value) || S.getId("wordIndex").value < 1) {
S.getId("wordIndex").value = 1;
} else if (S.getId("wordIndex").value > S.getId("solution").value.split(" ").length) {
S.getId("wordIndex").value = S.getId("solution").value.split(" ").length
}
var index = Number(S.getId("wordIndex").value) - 1;
var startingIndex = solutionIndex;
var word = S.getId("solution").value.split(" ")[index];
do {
if (solutionIndex < solutions.length - 1) {
solutionIndex++;
} else {
solutionIndex = 0;
}
} while (solutions[solutionIndex].split(" ")[index] == word && solutionIndex != startingIndex);
if (solutionIndex == startingIndex) {
alert("There's only one word which fits at the beginning of these solutions.");
} else {
navigate();
}
});
// gives the newCode button functionality
document.getElementById("newCode").addEventListener("click", function() {
document.getElementById("after").style.display = "none";
solutions = [];
document.getElementById("code").value = "";
document.getElementById("before").style.display = "block";
document.getElementById("solution").value = "";
});
});
function navigate() {
S.getId("solution").value = solutions[solutionIndex];
S.getId("solutionNumber").innerHTML = solutionIndex+1 + "/" + solutions.length;
}
function decode() {
let messenger = {};
worker.addEventListener("message", function (message) {
if (message.data.error) {
document.getElementById("during").style.display = "none";
document.getElementById("before").style.display = "block";
let styles = document.styleSheets[1].cssRules || document.styleSheets[1].rules;
S.forEach(styles, function (style) {
if (style.selectorText == ".cursor") {
style.style.cursor = "auto";
return "break";
}
});
S.makeDialog("The decoder encountered a problem.");
} else if (message.data.progress < 100) {
S.getId("progressBar").style.width = message.data.progress + "%";
} else {
S.getId("progressBar").style.width = message.data.progress + "%";
solutions = message.data.solutions;
if (solutions.length > 0) {
document.getElementById("solution").value = solutions[0];
S.getId("solutionNumber").textContent = "1/" + solutions.length;
} else {
document.getElementById("solution").value = "No solution was found.";
S.getId("solutionNumber").textContent = "0/0";
}
console.info("Time to decode = " + message.data.time + " seconds");
document.getElementById("during").style.display = "none";
document.getElementById("after").style.display = "block";
let styles = document.styleSheets[1].cssRules || document.styleSheets[1].rules;
S.forEach(styles, function (style) {
if (style.selectorText == ".cursor") {
style.style.cursor = "auto";
return "break";
}
});
S.getId("progressBar").style.width = "0%";
worker.removeEventListener("message", arguments.callee);
}
});
messenger.words = words;
messenger.verbs = verbs;
messenger.text = document.getElementById("code").value.toLowerCase();
worker.postMessage(messenger);
}
</script>
<link rel="stylesheet" href="https://epicenterprograms.github.io/standards/formatting/foundation.css">
<!--
<link rel="stylesheet" href="file:///C:/Users/rtben/Documents/GitHub/standards/formatting/foundation.css">
-->
<style>
.cursor {
cursor: auto;
}
#during {
display: none;
}
#progressContainer {
z-index: 1;
border: .05rem solid black;
border-radius: .25rem;
width: 30rem;
height: 1rem;
background: #aaa;
}
#progressBar {
z-index: -1;
float: left;
border-radius: .25rem;
width: 0%;
height: 100%;
background: #00e;
}
#after {
display: none;
}
</style>
</head>
<body>
<h1 class="main-title">
Decoder
</h1>
<main>
<br>
<div id="before">
<button onclick='window.location.href = "extras"'>
Explore extras
</button>
<br>
<br>
<textarea cols="60" rows="10" placeholder="Type the code here." id="code"></textarea>
<br>
<br>
<input type="text" placeholder="Exrta words to consider" id="extraWords" disabled>
<note-><div><div>Put in extra words you want to be considered separated by spaces. Possibilities include proper names and slang.</div></div></note->
<br>
<br>
<input typer="text" placeholder="Words to filter out" id="filter1" disabled>
<br>
<br>
<button type="button" id="decode">
Decode
</button>
</div>
<div id="during">
<h3 id="workingHeading">
Working...
</h3>
<div id="progressContainer">
<div id="progressBar"></div>
</div>
<!-- <progress id="progress"></progress> -->
</div>
<div id="after">
<textarea cols="60" rows="10" id="solution" readonly></textarea>
<br>
<br>
<button id="superFastLast">
<<<
</button>
<button id="fastLast">
<<
</button>
<button id="last">
<
</button>
<span id="solutionNumber">0/0</span>
<button id="next">
>
</button>
<button id="fastNext">
>>
</button>
<button id="superFastNext">
>>>
</button>
<br>
<br>
<input type="text" placeholder="Jump to item #:" id="jumpIndex">
<button id="jump">
Jump
</button>
<br>
<br>
<button id="findLast">
<
</button>
<input type="text" placeholder="Go to occurance of:" id="searchText">
<button id="findNext">
>
</button>
<br>
<br>
<button id="lastWord">
< Previous word
</button>
<input type="text" placeholder="Word #" style="width:5em" id="wordIndex">
<button id="nextWord">
Next word >
</button>
<div style="display:none">
<br>
<br>
<input type="text" placeholder="Word to filter">
<button id="filter2">
Filter
</button>
<select id="filteredWords">
<option value="" selected>
Filtered words
</option>
</select>
<button id="unfilter">
Unfilter
</button>
<button id="unfilterAll">
Unfilter all
</button>
</div>
<br>
<br>
<button type="button" id="newCode">
Try a new<br>
code
</button>
</div>
</main>
</body>
</html>