-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
71 lines (66 loc) · 2.31 KB
/
scripts.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
var settingsIcon = document.getElementById('settingsIcon');
var settings = document.getElementById('settings');
var darkMode = document.getElementById('darkMode');
var wrapper = document.getElementById('wrapper');
var stylesheet = document.getElementById('stylesheet');
settingsIcon.addEventListener('click', function () {
settings.style.display = 'block';
});
wrapper.addEventListener('click', function () {
settings.style.display = 'none';
});
if (localStorage.getItem('darkMode') == 'true') {
darkMode.checked = true;
stylesheet.href = 'dark.css';
} else {
darkMode.checked = false;
stylesheet.href = 'style.css';
}
darkMode.addEventListener('click', function () {
if (darkMode.checked) {
stylesheet.href = 'dark.css';
localStorage.setItem('darkMode', 'true');
} else {
stylesheet.href = 'style.css';
localStorage.setItem('darkMode', 'false');
}
});
var bday;
if (localStorage.getItem('bday')) {
document.getElementById('dateIn').value = localStorage.getItem('bday');
firstLaunch.style.display = 'none';
wrapper.style.display = 'flex';
bday = localStorage.getItem('bday')
updateAge();
}
var ageForm = document.getElementById('ageForm');
ageForm.addEventListener('submit', function (e) {
e.preventDefault();
firstLaunch.style.display = 'none';
wrapper.style.display = 'flex';
bday = document.getElementById('dateIn').value;
updateAge();
});
var settingsForm = document.getElementById('settingsForm');
settingsForm.addEventListener('submit', function (e) {
e.preventDefault();
bday = document.getElementById('dateInUpdate').value;
settings.style.display = 'none';
updateAge();
});
function updateAge() {
settingsIcon.style.display = 'block';
var time = new Date();
// var bday = new Date("2004-01-18");
var bdayVal = new Date(bday);
localStorage.setItem('bday', bday);
var year = time.getFullYear() - bdayVal.getFullYear();
var msec = time.getTime() - bdayVal.getTime();
var msecString = msec.toString();
var decimalPart = msecString.slice(0, 2);
var fractionalPart = msecString.slice(2);
document.getElementById('monitor').textContent = year;
document.getElementById('monitor2').textContent = '.' + decimalPart + fractionalPart;
requestAnimationFrame(updateAge);
}
// updateAge();