-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounter.js
183 lines (116 loc) · 4.5 KB
/
counter.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
//window.onload = function(){
const theDay = document.querySelector(".theDay");
const selectDay = document.querySelector(".form-select");
const resultDays = document.querySelector(".resultDays");
let cssPath = document.getElementById("theme");
let cssStyle = document.querySelector(":root");
//let dataThemeBasic = document.body.getAttribute("data-theme", "Valitse päivä ylävalikosta");
//dataThemeBasic = "Valitse"
let dataTheme = document.body.setAttribute("data-theme", "Valitse-päivä-ylävalikosta")
const theValue = selectDay.value;
//theDay.innerHTML = "Valitse päivä ylävalikosta"
theDay.innerHTML = theValue ;
function changeDay(){
//theDay.innerHTML = theValue ;
const theValue = selectDay.value;
theDay.innerHTML = theValue + "\n" +theDates[theValue].day + "." + (theDates[theValue].month + 1); //+ 1 because the counter starts from 0=jan
if(theValue == "Valitse Valitse päivä ylävalikosta"){
theDay.innerHTML = "Valitse päivä ylävalikosta"
resultDays.innerHTML = "..."
document.body.setAttribute("data-theme", "Ystävänpäivä")
}else{
counter(theValue);
}
}
//A tree for the dates. Having this many css-files would be harder to manage, even it would be intuitive,
//but easier to have data-theme attributes defined in css. This way we do not even have to define the
//attributes in these object
const theDates = {
"Valitse päivä ylävalikosta" :{
month: " ",
day: " ",
sub: " ",
href: "./resources/css/independent.css"
},
Itsenäisyyspäivä : {
month: 11,
day: 6,
sub: "itsenäisyyspäivään",
href: "./resources/css/independent.css"
},
Joulu : {
month: 11,
day: 24,
sub: "jouluun",
href: "./resources/css/style.css"
},
Uusivuosi : {
month: 11,
day: 31,
sub: "uuteenvuoteen",
href: "./resources/css/valentines.css"
},
Vappu:{
month: 4,
day: 1,
sub: "vappuun",
href: "./resources/css/valentines.css"
},
Ystävänpäivä : {
month: 1,
day: 14,
sub: "ystävänpäivään",
href: "./resources/css/valentines.css",
}
}
function counter(theValue){
//moving these variables made the counter dates correct
const dayValue = theDates[theValue].day;
const monthValue = theDates[theValue].month;
let today = new Date();
let christmasYear = today.getFullYear();
if(today.getMonth() == monthValue && today.getDate() > dayValue){
christmasYear = christmasYear + 1;
}
let christmasDate = new Date(christmasYear, monthValue, dayValue);
let dayMilliseconds = 1000 * 60 * 60 * 24;
let remainingDays = Math.ceil((christmasDate.getTime() - today.getTime()) / (dayMilliseconds));
//document.body.setAttribute("data-theme", [theValue]);
//changes the theme
if(remainingDays > 0){
resultDays.innerHTML = remainingDays + "\n" + "päivää " + theDates[theValue].sub;
}else if(remainingDays < 0){
resultDays.textContent = (remainingDays + 365) + "\n" + "päivää " + theDates[theValue].sub;
}//if you want to count the actual ending day as well, put 366
changeThemes(theValue);
};
//} //onload end
function changeThemes(theValue){
const gnomeBtn = document.querySelector(".gnomeBtn");
//gnomeMeme.style.opacity = "0";
if(theValue === "Joulu"){
//const gnomeBtn = document.createElement("button");
//const resultContainer = document.querySelector(".resultContainer");
//resultContainer.appendChild(gnomeBtn);
//gnomeBtn.classList.add("gnomeBtn");
// gnomeBtn.innerHTML = "Click me";
gnomeBtn.style.opacity = "1";
gnomeBtn.addEventListener("click", gnomeAttack);
document.body.setAttribute("data-theme", "Joulu");
}else if(theValue === "Valitse päivä ylävalikosta"){
theDay.innerHTML = "Valitse päivä ylävalikosta"
document.body.setAttribute("data-theme", "Valitse-päivä-ylävalikosta")
remainingDays = 0;
resultDays.innerHTML = "..."
gnomeBtn.style.opacity = "0";
}else{
document.body.setAttribute("data-theme", [theValue]);
gnomeBtn.style.opacity = "0";
}
}
function gnomeAttack(){
let gnomeNum = 0;
resultDays.innerHTML = gnomeNum;
const gnomeMeme = document.querySelector(".gnomeMeme");
gnomeMeme.style.opacity = "1";
}