-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathscript.js
218 lines (186 loc) · 6.05 KB
/
script.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
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
//Google Analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-79436930-3']);
(function () {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
var inputBox;
$(document).ready(function () {
inits();
setTimeout(delayedInits, 1000)
});
function inits() {
$.supportsIsTrusted = () => {
return false
};
inputBox = $(".js-input-box");
$("button:contains('Skip Video')").trigger("click");
$("button:contains('Continue')").trigger("click");
const continueTo = $("a:contains('Continue To:')");
if (continueTo.length)
window.location.href = continueTo.get(0).href // Go to the continue to the next lesson link
}
function delayedInits() {
setTimeout(start, 1000)
}
function start() {
if (singleLetterSelector().length > 0)
startSingleLetter();
else if (screenIntroSelector().length > 0)
startScreenIntro();
else if (screenBasicSelector().length > 0)
startScreenBasic();
else if (screenFallingSelector().length > 0)
startScreenFalling();
else if (nitroTypeSelector().length > 0)
startNitroType();
}
function singleLetterSelector() {
return $(".structure-content").not(".hide").find(".frame")
}
function startSingleLetter() {
typeLetter(singleLetterSelector().find(".key-label")[0].textContent)
setTimeout(() => {
pressEnter();
setTimeout(start, 500)
}, 500)
_gaq.push(['trackEvent', 'site', 'single_letter']);
}
function screenIntroSelector() {
return $(".structure-content").not(".hide").find(".screenIntro")
}
function startScreenIntro() {
var letters = [];
const letterObjects = screenIntroSelector().find(".letter");
for (var i = 0; i < letterObjects.length; i++)
letters.push(letterObjects[i].textContent);
typeLetters(letters)
_gaq.push(['trackEvent', 'site', 'screen_intro']);
}
function screenBasicSelector() {
return $(".structure-content").not(".hide").find(".screenBasic")
}
function startScreenBasic() {
var letters = [];
const letterObjects = screenBasicSelector().find(".letter");
for (var i = 0; i < letterObjects.length; i++)
letters.push(letterObjects[i].textContent);
typeLetters(letters)
_gaq.push(['trackEvent', 'site', 'screen_basic']);
}
function screenFallingSelector() {
return $(".structure-content").not(".hide").find(".screenFalling")
}
function startScreenFalling() {
var letters = [];
const letterObjects = screenFallingSelector().find(".letter");
for (var i = 0; i < letterObjects.length; i++)
letters.push(letterObjects[i].textContent.substring(1, 2));
typeLetters(letters.reverse())
_gaq.push(['trackEvent', 'site', 'screen_falling']);
}
function nitroTypeSelector() {
return $("#race-track")
}
function startNitroType() {
inputBox = $("body");
String.prototype._wordwrap = String.prototype.wordwrap;
String.prototype.wordwrap = function (number) {
if (this !== "Please wait. Typing content will appear before the race begins") {
setTimeout(() => {
typeLetters(this)
}, 4200)
}
return this._wordwrap(number)
}
_gaq.push(['trackEvent', 'site', 'nitro_type']);
}
function typeLetters(letterList) {
var speed;
var accuracy;
var intervalRate;
var interval;
var letterIndex = 0; // The current letter in the array
var running = false;
const updateSettingsListener = (e) => {
var data = e.detail;
var newAccuracy = parseInt(data.accuracy);
var newSpeed = parseInt(data.speed);
if (newAccuracy !== accuracy || newSpeed !== speed) {
speed = newSpeed;
accuracy = newAccuracy;
intervalRate = 60000 / ((4 + 1) * speed); // 4 is average word length that typing.com seems to use, +1 because of the space after the word
stopInterval();
interval = startInterval();
running = true;
_gaq.push(['trackEvent', 'typing', 'wpm_or_accuracy_change']);
}
};
const updateStateListener = (e) => {
var newRunning = e.detail;
if (newRunning !== running) {
running = newRunning;
if (!running) {
stopInterval();
running = false;
_gaq.push(['trackEvent', 'typing', 'paused']);
} else {
stopInterval();
interval = startInterval();
running = true;
_gaq.push(['trackEvent', 'typing', 'started']);
}
}
};
document.addEventListener('updateSettings', updateSettingsListener);
document.addEventListener('updateState', updateStateListener);
const startInterval = function () {
return setInterval(function () {
if (letterIndex < letterList.length) {
typeLetter(letterList[letterIndex]);
letterIndex++
} else {
setTimeout(pressEnter, 500);
}
}, intervalRate);
};
const stopInterval = () => {
clearInterval(interval);
};
}
function pressEnter() {
var e = jQuery.Event("keydown");
e.which = 13;
addEmptyEventFunctions(e);
e.originalEvent = JSON.parse(JSON.stringify(e));
addEmptyEventFunctions(e);
inputBox.trigger(e);
}
var firstLetter = true;
function typeLetter(letter) {
if (firstLetter) {
_gaq.push(['trackEvent', 'typing', 'first_letter_typed']);
firstLetter = false
}
var e = jQuery.Event("keypress");
e.key = letter;
e.which = letter.charCodeAt(0);
e.keyCode = e.which;
if (e.which === 160)
e.key = " ";
addEmptyEventFunctions(e);
e.originalEvent = JSON.parse(JSON.stringify(e));
addEmptyEventFunctions(e.originalEvent);
inputBox.trigger(e);
}
function addEmptyEventFunctions(e) {
e.preventDefault = () => {
};
e.stopPropagation = () => {
};
}