-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
189 lines (141 loc) · 3.86 KB
/
app.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
// TO DO
//1. display 25 minutes on the screen -- DONE
//2. interval by seconds the 25 minutes -- DONE
//3. stop button should work -- DOne
//4. Perhaps include an API to encourage qutoes every 5 minutes
//5. CSS -- DONE
//space bar control
// mobile ???
//post grading
// need to be clear on the THREE MAIN TOPICS
// * Procrastination
// * Diffuse and Focused Learning
// * Chunking
var currentTime;
var futureTime;
var displayTime;
var difference;
var interval;
var timerStarted = false;
var timerPaused = false;
var focusTimerLength = 25;
var relaxTimerLength = 5;
var state = 'focus'; //either focus or relax
var phrases = ['overcome procrastination',
'engage your acetylcholine neurons',
"aren't tomatoes red?",
'chunking, big picture, and context',
"process over product",
"deliberate practice makes you stronger",
"don't look here, focus",
"make this fullscreen with F11",
"kudos to Francesco Cirillo",
'no interuptions',
'neurodiscomfort only lasts a couple minutes']
var relaxPhrases = ['a diffuse mind is a wonderful thing',
'release your octopus',
'Salvador Dali, Thomas Edison...',
'remember to treat yourself',
'you deserve a reward',
'build the habit and reward yourself']
$("#info").click( function () {
//console.log('modal loaded?')
$('.modal').modal('show');
});
$("#start").click(function () {
// alert("Handler for .click() called.");
console.log('click')
if (timerStarted == false && state == 'focus') {
createTime(focusTimerLength)
var phrase = phraseSelector()
$('.encouragement').html(phrase)
startTimer()
}
if (timerStarted == false && state == 'relax') {
createTime(relaxTimerLength)
var phrase = phraseSelector()
$('.encouragement').html(phrase)
startTimer()
}
if (timerPaused == true) {
startTimer()
timerPaused = false;
var phrase = phraseSelector()
$('.encouragement').html(phrase)
}
});
$("#stop").click(function () {
stopTimer()
});
function createTime(timerLength) {
currentTime = moment()
futureTime = moment().add(timerLength, 'm')
}
function stopTimer() {
clearInterval(interval)
timerPaused = true;
}
function phraseSelector() {
if (state == 'focus') {
var selection = Math.floor((Math.random() * phrases.length));
return phrases[selection]
}
else if (state == 'relax') {
var selection = Math.floor((Math.random() * relaxPhrases.length));
return relaxPhrases[selection]
}
}
function startTimer() {
timerStarted = true
//probably should set this to a variable so that I can refer back to it and reset it ?
interval = setInterval(count, 1000);
}
function count() {
//counts down and updates the screen
//increases the time
futureTime = futureTime - 1000;
difference = futureTime - currentTime
displayTime = moment(difference).format("mm:ss")
//updates the time left
$("#counter").html(displayTime);
$("#counter-title").html(displayTime);
if (difference % 300000 == 0) {
var phrase = phraseSelector()
$('.encouragement').html(phrase)
console.log('TRIGGERED')
}
// when display time shows 00:00
if (displayTime == '00:00') {
if (state == 'focus') {
clearInterval(interval)
$('body').addClass('relax')
$('body').removeClass('focus')
timerStarted = false;
$("#counter").html(displayTime);
setTimeout(setMood, 3900)
state = 'relax'
$('.encouragement').html('click start to relax')
$("#counter").html('5:00')
}
else if (state == 'relax') {
clearInterval(interval)
$('body').addClass('focus')
$('body').removeClass('relax')
timerStarted = false;
$("#counter").html(displayTime);
setTimeout(setMood, 3900)
$('.encouragement').html('click start to focus again')
$("#counter").html('25:00')
state = 'focus'
}
// triggers the animimation
}
}
function setMood() {
if (state == 'relax') {
$("body").css("background-color", "#DD5713");
}
else if (state == 'focus') {
$("body").css("background-color", "#007ACC");
}
}