-
Notifications
You must be signed in to change notification settings - Fork 0
/
repo.js
84 lines (73 loc) · 1.63 KB
/
repo.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
'use strict';
function end_timer(){
if(core_storage_data['audio']){
audio_start('boop');
}
core_elements['box'].style.backgroundColor = '#' + core_random_hex();
}
function repo_escape(){
reset();
}
function repo_init(){
core_repo_init({
'events': {
'start-button': {
'onclick': start,
},
},
'globals': {
'change_time': false,
'start_time': false,
},
'storage': {
'audio': true,
},
'storage-menu': '<table><tr><td><input id=audio type=checkbox><td>Audio</table>',
'title': 'ReactionTest.htm',
'ui-elements': [
'box',
'result',
'start-button',
],
});
}
function reset(){
core_interval_pause_all();
Object.assign(
core_elements['start-button'],
{
'onclick': start,
'textContent': 'Start Timer',
}
);
}
function start(){
start_time = date_to_timestamp();
change_time = core_random_integer({
'max': 9000,
}) + 999;
core_interval_modify({
'id': 'timer',
'interval': change_time,
'set': 'setTimeout',
'todo': end_timer,
});
core_elements['box'].style.backgroundColor = '#000';
Object.assign(
core_elements['start-button'],
{
'onclick': stop,
'textContent': 'Stop Timer',
}
);
}
function stop(){
if(core_intervals['timer']['paused']){
return;
}
reset();
const final_time = -(change_time - (date_to_timestamp() - start_time));
core_elements['result'].textContent = final_time > 0
? '+' + final_time + 'ms'
: 'Too soon!';
}