-
Notifications
You must be signed in to change notification settings - Fork 3
/
quarantine.html
255 lines (201 loc) Β· 6.71 KB
/
quarantine.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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<title>MoodGrid</title>
<meta name="description" content="Mood Meter">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="manifest" href="site.webmanifest">
<link rel="apple-touch-icon" href="icon.png">
<!-- Place favicon.ico in the root directory -->
<link rel="stylesheet" href="scss/styles.css">
<meta name="theme-color" content="#fafafa">
<link href="https://fonts.googleapis.com/css?family=Overlock:900&display=swap" rel="stylesheet">
</head>
<body>
<!--[if IE]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="https://browsehappy.com/">upgrade your browser</a> to improve your experience and security.</p>
<![endif]-->
<!-- Add your site or application content here -->
<section class="top">
<h1>
MoodGrid
</h1>
<button id="toggleTips">Tips</button>
<button class="chart"><a href="/chart.html">Chart</a></button>
</section>
<div class="container">
<section class="mood-chart quarantine"></section>
</div>
<div class="tips">
<p>Tips:</p>
<ul>
<li>"Shift + Click" to remove a selection</li>
<li>"Ctrl" to highlight keyboard shortcuts values</li>
<li>
"R", "Y", "B", "G" to focus on the respective quadrant, then:
<ul>
<li>type the number to select the respective mood</li>
<li>press "-" and type the number to remove a selection on that mood</li>
</ul>
</li>
</ul>
</div>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.14.3/firebase.js"></script>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "AIzaSyAvBoHxYKjWaaP5lWLTzps9w_nx-y7UmQw",
authDomain: "mood-meter-grid.firebaseapp.com",
databaseURL: "https://mood-meter-grid.firebaseio.com",
projectId: "mood-meter-grid",
storageBucket: "mood-meter-grid.appspot.com",
messagingSenderId: "248460628048",
appId: "1:248460628048:web:79cbe1abaef57caac80155"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// Get a reference to the database service
var database = firebase.database();
function writeMood(moodColor, moodName) {
database.ref('mood').push({
moodColor,
moodName,
created: Date.now()
})
}
const emojis = ['π€', 'πΎ', 'π¦', 'π', 'π¦', 'πΆ', 'π¨', 'πΌ', 'π²', 'π'];
let emojiCount = 0;
document.querySelector('#toggleTips').addEventListener('click', () => {
document.querySelector('.tips').classList.toggle('show');
});
function resetMood(mood) {
mood.classList.remove('selected');
delete mood.dataset.clickcount;
delete mood.dataset.emoji;
delete mood.dataset.content;
}
function selectMood(mood, isReduce = false, isReset = false) {
mood.dataset.clickcount = isReduce
? parseInt(mood.dataset.clickcount || 0) - 1
: parseInt(mood.dataset.clickcount || 0) + 1;
if (isReset || mood.dataset.clickcount <= 0) {
resetMood(mood);
return;
}
writeMood(mood.dataset.moodcolor, mood.dataset.moodname);
if (mood.classList.contains('selected')) {
mood.dataset.content = `
${mood.dataset.emoji}
${mood.dataset.clickcount > 1 ? ` + ${mood.dataset.clickcount - 1}` : ''}
`;
return;
}
mood.classList.add('selected');
mood.dataset.emoji = emojis[emojiCount];
emojiCount = emojiCount + 1 >= emojis.length
? Math.floor(Math.random() * emojis.length)
: (emojiCount + 1);
mood.dataset.content = mood.dataset.emoji;
}
function setQuadrant(keyValue) {
if (keyValue) {
pressedQuadrant = keyValue;
document.querySelector('.mood-chart').dataset.highlight = pressedQuadrant;
return;
}
pressedQuadrant = null;
delete document.querySelector('.mood-chart').dataset.highlight;
}
function mountMoodMeter() {
const moods = {
red: ['Furious', 'Protesting', 'A', 'B', 'C', 'D'],
yellow: ['Went outside', 'Happy', 'Social', 'Healthy', 'C', 'D'],
blue: ['Exhausted', 'Tired', 'Sick', 'Depressed', 'C', 'D'],
green: ['Cozy', 'Serene', 'Mellow', 'A', 'C', 'D'],
};
Object.keys(moods).forEach(color => {
const quadrant = document.createElement('div');
quadrant.classList.add('mood-quadrant');
moods[color].forEach((mood, index) => {
const moodBtn = document.createElement('button');
moodBtn.classList.add('mood', color);
moodBtn.dataset.tip = `${color[0].toUpperCase()}${index + 1}`;
moodBtn.dataset.moodcolor = color;
moodBtn.dataset.moodname = mood;
moodBtn.textContent = mood;
moodBtn.addEventListener('click', (e) => selectMood(e.target, e.shiftKey));
moodBtn.addEventListener('keydown', (e) => {
if (e.key === 'Delete') {
resetMood(e.target);
};
if (e.key === 'Backspace' || e.key === '-') {
selectMood(e.target, true);
};
});
quadrant.append(moodBtn);
});
document.querySelector('.mood-chart').append(quadrant);
})
}
let pressedQuadrant = null;
let pressedNumber = null;
let timeoutId = null;
let setToReduce = false;
document.body.addEventListener('keydown', (e) => {
if (e.ctrlKey) {
document.querySelector('.mood-chart').classList.add('show-tip');
}
if (['R', 'Y', 'B', 'G'].includes(e.key.toUpperCase())) {
setQuadrant(e.key.toUpperCase())
}
if (pressedQuadrant && e.key === '-') {
setToReduce = true;
}
if (pressedQuadrant && parseInt(e.key) <= 9) {
pressedNumber = `${pressedNumber || ''}${e.key}`;
if (timeoutId) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(() => {
const mood = document.querySelector(`[data-tip=${pressedQuadrant}${pressedNumber}]`);
if (setToReduce) {
selectMood(mood, true);
setToReduce = false;
} else {
selectMood(mood);
}
pressedNumber = null;
setQuadrant()
}, 300);
e.preventDefault();
}
if (pressedQuadrant && e.key === 'Escape') {
timeoutId = null;
pressedNumber = null;
setToReduce = false;
setQuadrant();
}
});
document.body.addEventListener('keyup', (e) => {
if (e.key === 'Control') {
document.querySelector('.mood-chart').classList.remove('show-tip');
if (!timeoutId) {
pressedNumber = null;
setQuadrant();
}
}
});
mountMoodMeter();
</script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-45807498-10"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'UA-45807498-10');
</script>
</body>
</html>