forked from JoshuaGrams/steno-jig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgutenberg.html
132 lines (114 loc) · 3.49 KB
/
gutenberg.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Steno Jig</title>
<link href="style.css" rel="stylesheet" type="text/css">
<script src="type-jig.js"></script>
<script src="steno-display.js"></script>
<script src="plover-translations.js"></script>
<script src="gutenberg.js"></script>
<link rel="stylesheet" type="text/css" href="font-roboto.css">
</head>
<body>
<div id="lesson">
<h3 id="lesson-name" class="center"></h3>
<div class="scroll-margin"><div id="strokes"></div></div>
<div class="scroll-bounds"><div id="exercise" style="white-space: nowrap"></div></div>
<div id="answer" class="answer scroll-margin" contenteditable="true"><span class="prompt">Type here...</span></div>
<p id="clock" class="clock"></p>
<p class="center">
<a id="back">← Back to Menu</a>
<a id="again">↺ Repeat Drill</a>
<a id="new">→ New Drill</a>
</p>
<p id="error-log"></p>
</div>
<script>
function new_rng(seed_txt) {
var s, i, j, tmp
s = new Array(256);
for (i = 0; i < 256; ++i) {
s[i] = i;
}
if (seed_txt == null) {
seed_txt = Math.random().toString()
}
for (i = j = 0; i < 256; ++i) {
j += s[i] + seed_txt.charCodeAt(i % seed_txt.length);
j %= 256;
tmp = s[i]; s[i] = s[j]; s[j] = tmp;
}
return function() {
var p, ret = 0
for (p = 0; p < 7; ++p) {
ret *= 256
i = (i + 1) % 256;
j = (j + s[i]) % 256;
tmp = s[i]; s[i] = s[j]; s[j] = tmp;
ret += s[(s[i] + s[j]) % 256];
}
return ret / 72057594037927935.0
}
}
function parseQueryString() {
var vars = {};
var query = document.location.search.substring(1);
var pairs = query.replace(/\+/g,'%20').split('&');
for (var i = 0; i < pairs.length; ++i) {
var name, value='';
var n = pairs[i].indexOf('=');
if (n === -1) {
name = decodeURIComponent(pairs[i]);
} else {
name = decodeURIComponent(pairs[i].substring(0, n));
value = decodeURIComponent(pairs[i].substring(n+1));
}
vars[name] = value;
}
return vars;
}
window.onload = function() {
var fields = parseQueryString()
var rng = new_rng(fields.seed)
var top_n = fields.top == null ? 100 : parseInt(fields.top)
// round up
top_n = Math.floor((top_n + 99) / 100) * 100
if (top_n < 100) {
top_n = 100
}
if (top_n > 8000) {
top_n = 8000
}
var word_count = fields.word_count == null ? 100 : parseInt(fields.word_count)
var name = "Sentences from Project Gutenberg that contain only the top " + top_n + " words.";
var hints = null;
if(fields.hints) {
var translations = TypeJig.shortestTranslations(TypeJig.Translations.Plover);
hints = new StenoDisplay('strokes', translations, true);
}
let words = [], sentence, i
let chars_left = word_count * 5
let top_n_bucket = window.sentences_by_top_100[top_n / 100 - 1]
while (chars_left > 0) {
sentence = top_n_bucket[Math.floor(rng() * top_n_bucket.length)]
chars_left -= sentence.length
words.splice(0, 0, ...sentence.split(' '))
}
var exercise = new TypeJig.Exercise(words, 0, false, 'ordered');
var h = document.getElementById('lesson-name');
h.appendChild(document.createTextNode(name));
document.title = name + ' - ' + document.title;
var back = document.getElementById('back');
back.href = './form.html';
var again = document.getElementById('again');
again.href = document.location.href;
var new_drill = document.getElementById('new');
new_drill.href = document.location.href.toString().replace(/seed=([^&#]*)/, 'seed=' + Math.random().toString());
var jig = new TypeJig(exercise, 'exercise', 'answer', 'clock', hints);
}
</script>
</body>
</html>