-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
135 lines (114 loc) · 3.39 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
const day = document.querySelectorAll('.day');
const dayBlock = document.querySelectorAll('.day-block');
const dayLeft = document.querySelectorAll('.day-left');
const dayNum = document.querySelectorAll('.day-num');
const dayYear = document.querySelector('.day-year');
const content = document.querySelector('.content');
const hourSelector = document.querySelector('.hour');
const minuteSelector = document.querySelector('.minute');
const secondSelector = document.querySelector('.second');
const indicatorSelector = document.querySelector('.indicator');
const d = new Date();
const month = d.getMonth();
const date = d.getDate();
let hour = d.getHours();
const hour2 = d.getHours();
const minute = d.getMinutes();
const seconds = d.getSeconds();
function getTime() {
if (hour >= 12) {
hour -= 12;
}
if (hour < 10) {
hourSelector.innerHTML = `0${hour}`;
} else {
hourSelector.innerHTML = hour;
}
if (hour2 < 12) {
indicatorSelector.innerHTML = ' AM';
} else {
indicatorSelector.innerHTML = ' PM';
}
if (minute < 10) {
minuteSelector.innerHTML = `0${minute}`;
} else {
minuteSelector.innerHTML = minute;
}
if (seconds < 10) {
secondSelector.innerHTML = `0${seconds}`;
} else {
secondSelector.innerHTML = seconds;
}
setTimeout(getTime, 1000);
}
getTime();
function applyDayYear() {
let count = 0;
for (let i = 0; dayBlock.length; i++) {
if (dayBlock[i] === undefined) {
break;
}
let theChildren = dayBlock[i].children;
let sum = dayBlock[i].childElementCount;
for (let j = 0; j < theChildren.length; j++) {
if (theChildren[j].classList.contains('crossed')) {
sum--;
}
}
count += sum;
}
dayYear.textContent = count;
}
function applyDayNum() {
for (let i = 0; dayBlock.length; i++) {
if (dayBlock[i] === undefined) {
break;
}
let theChildren = dayBlock[i].children;
let count = dayBlock[i].childElementCount;
for (let j = 0; j < theChildren.length; j++) {
if (theChildren[j].classList.contains('crossed')) {
count--;
}
}
if (count === 1) {
dayNum[i].textContent = `${count} Day Left`;
} else if (count === 0) {
dayNum[i].textContent = 'Move on!';
} else {
dayNum[i].textContent = `${count} Days Left`;
}
}
}
for (let i = 0; i < content.children.length; i++) {
for (let k = 0; k <= month; k++) {
if ('month-' + k !== content.children[i].id) {
if (content.children[k - 1] === undefined) {
continue;
}
let count = content.children[k - 1].children[1].childElementCount;
for (let w = 0; w < count; w++) {
content.children[k - 1].children[1].children[w].classList.add('crossed');
applyDayNum();
applyDayYear();
}
}
if ('month-' + k === content.children[i].id) {
let contentChildren = content.children[i].children;
for (let z = 0; z < contentChildren.length; z++) {
if (contentChildren[z].classList.contains('day-block')) {
let contentDays = contentChildren[z].children;
for (let p = 0; p < contentDays.length; p++) {
for (let m = 1; m <= date; m++) {
if (contentDays[p].textContent === (m - 1).toString()) {
contentDays[p].classList.add('crossed');
applyDayNum();
applyDayYear();
}
}
}
}
}
}
}
}