forked from h5bp/html5-boilerplate
/
script.js
49 lines (46 loc) · 1.19 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
/* Author: Dean Brettle
* Copyright 2011
* Licensed under the terms of the AGPL3.
*/
as = {
interval: 60000,
factor: 1.2,
efficiency: 0.0,
history: [],
focusedCount: 0,
start: function() {
window.setTimeout(as.playAudio, 10000 + as.interval * Math.random());
},
playAudio: function() {
var audioPrompt;
if (!audioPrompt) {
audioPrompt = $("#audioPrompt")[0];
audioPrompt.addEventListener("ended", as.prompt);
}
audioPrompt.currentTime = 0.0;
audioPrompt.play();
},
prompt: function() {
var focused = window.confirm("How's it going?");
if (focused) {
as.interval = as.interval * as.factor;
}
else {
as.interval = as.interval / as.factor;
}
as.history.push(focused);
as.focusedCount += focused;
as.efficiency = 1.0*as.focusedCount/as.history.length;
as.displayStats();
as.start();
},
displayStats: function() {
$("#efficiency").html(Math.round(as.efficiency*100));
$("#attentionSpan").html(Math.round(as.interval/2.0/60000));
$("#samples").html(as.history.length);
}
};
$(function() {
as.displayStats();
as.start();
});