-
Notifications
You must be signed in to change notification settings - Fork 0
/
season.html
278 lines (233 loc) · 11.2 KB
/
season.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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Which Season Are We In?</title>
<link rel="shortcut icon" type="image/png" href="img/favicon.png"/>
<link rel="stylesheet" type="text/css" href="style_season.css">
</head>
<body class = "strokeme">
<div id="background_tweaks">
<header>
<span class="season_name_span">...</span>
</header>
<div id="description">
<p>We are currently in<span class="season_name_span">...</span>.</p>
<p id="season_catchphrase">...</p>
</div>
<div id="proverbs">
<p id="main_proverb_phrase">Here are some sayings about this season:</p>
</div>
</div>
</body>
<script>
Date.fromJulian = function (j) {
j = (+j) + (30.0 / (24 * 60 * 60));
var A = Date.julianArray(j, true);
return new Date(Date.UTC.apply(Date, A));
};
Date.julianArray = function (j, n) {
var F = Math.floor;
var j2, JA, a, b, c, d, e, f, g, h, z;
j += 0.5;
j2 = (j - F(j)) * 86400.0;
z = F(j);
f = j - z;
if (z < 2299161) a = z;
else {
g = F((z - 1867216.25) / 36524.25);
a = z + 1 + g - F(g / 4);
}
b = a + 1524;
c = F((b - 122.1) / 365.25);
d = F(365.25 * c);
e = F((b - d) / 30.6001);
h = F((e < 14) ? (e - 1) : (e - 13));
JA = [F((h > 2) ? (c - 4716) : (c - 4715)),
h - 1, F(b - d - F(30.6001 * e) + f)];
var JB = [F(j2 / 3600), F((j2 / 60) % 60), Math.round(j2 % 60)];
JA = JA.concat(JB);
if (typeof n == 'number') return JA.slice(0, n);
return JA;
};
Date.getSeasons = function (y, wch) {
y = y || new Date().getFullYear();
if (y < 1000 || y > 3000) throw y + ' is out of range';
var Y1 = (y - 2000) / 1000,
Y2 = Y1 * Y1,
Y3 = Y2 * Y1,
Y4 = Y3 * Y1;
var jd, t, w, d, est = 0,
i = 0,
Cos = Math.degCos,
A = [y],
e1 = [485, 203, 199, 182, 156, 136, 77, 74, 70, 58, 52, 50, 45, 44, 29, 18, 17, 16, 14, 12, 12, 12, 9, 8],
e2 = [324.96, 337.23, 342.08, 27.85, 73.14, 171.52, 222.54, 296.72, 243.58, 119.81, 297.17, 21.02,
247.54, 325.15, 60.93, 155.12, 288.79, 198.04, 199.76, 95.39, 287.11, 320.81, 227.73, 15.45],
e3 = [1934.136, 32964.467, 20.186, 445267.112, 45036.886, 22518.443,
65928.934, 3034.906, 9037.513, 33718.147, 150.678, 2281.226,
29929.562, 31555.956, 4443.417, 67555.328, 4562.452, 62894.029,
31436.921, 14577.848, 31931.756, 34777.259, 1222.114, 16859.074];
while (i < 4) {
switch (i) {
case 0:
jd = 2451623.80984 + 365242.37404 * Y1 + 0.05169 * Y2 - 0.00411 * Y3 - 0.00057 * Y4;
break;
case 1:
jd = 2451716.56767 + 365241.62603 * Y1 + 0.00325 * Y2 + 0.00888 * Y3 - 0.00030 * Y4;
break;
case 2:
jd = 2451810.21715 + 365242.01767 * Y1 - 0.11575 * Y2 + 0.00337 * Y3 + 0.00078 * Y4;
break;
case 3:
jd = 2451900.05952 + 365242.74049 * Y1 - 0.06223 * Y2 - 0.00823 * Y3 + 0.00032 * Y4;
break;
}
t = (jd - 2451545.0) / 36525;
w = 35999.373 * t - 2.47;
d = 1 + 0.0334 * Cos(w) + 0.0007 * Cos(2 * w);
est = 0;
for (var n = 0; n < 24; n++) {
est += e1[n] * Cos(e2[n] + (e3[n] * t));
}
jd += (0.00001 * est) / d;
A[++i] = Date.fromJulian(jd);
}
return wch && A[wch] ? A[wch] : A;
};
Math.degRad = function (d) {
return (d * Math.PI) / 180.0;
};
Math.degSin = function (d) {
return Math.sin(Math.degRad(d));
};
Math.degCos = function (d) {
return Math.cos(Math.degRad(d));
};
var curr = 0;
function nextProverb(pl){
pl[curr].classList.toggle('hidden');
curr = (curr + 1) % pl.length;
pl[curr].classList.toggle('hidden');
}
seasonalPageGen = function (hemi,pvbs) {
var mine = Date.getSeasons();
today = new Date(); //Date.parse('Mar 21, 2014'); //use Date.parse() to check dates other than today
var parser = new DOMParser();
firstSpring = mine[1];
firstSummer = mine[2];
firstFall = mine[3];
firstWinter = mine[4];
var maxSpring = 3;
var maxSummer = 3;
var maxFall = 3;
var maxWinter = 3;
if (today >= firstSpring && today < firstSummer) {
Array.from(document.getElementsByClassName("season_name_span")).forEach(function(e){
e.innerHTML = (hemi === 'N' ? " Spring" : " Autumn");
});
document.getElementById("season_catchphrase").innerHTML = pvbs['Season'][(hemi === 'N' ? 'Spring' : 'Fall')]['Catchphrase'];
pvbs['Season'][(hemi === 'N' ? 'Spring' : 'Fall')]['Proverbs'].forEach(function(e){
var elemDiv = document.createElement("div");
var elemPphrase = document.createElement("p");
var elemPinfo = document.createElement("p");
elemDiv.classList.add('hidden','proverb');
elemPphrase.appendChild(parser.parseFromString('<span>' + e['Content'] + '</span>', "text/html").body);
elemPinfo.appendChild(document.createTextNode(e['Author'] + (e['From'] === "" ? "" : " - " + e['From'])));
elemDiv.appendChild(elemPphrase);
elemDiv.appendChild(elemPinfo);
document.getElementById("proverbs").appendChild(elemDiv);
});
document.body.style.backgroundImage = "url('img/" + (hemi === 'N' ? "spring/spring" : "fall/fall") + Math.floor(Math.random() * (hemi === 'N' ? maxSpring : maxFall) + 1) + ".jpg')";
} else if (today >= firstSummer && today < firstFall) {
Array.from(document.getElementsByClassName("season_name_span")).forEach(function(e){
e.innerHTML = (hemi === 'N' ? " Summer" : " Winter");
});
document.getElementById("season_catchphrase").innerHTML = pvbs['Season'][(hemi === 'N' ? 'Summer' : 'Winter')]['Catchphrase'];
pvbs['Season'][(hemi === 'N' ? 'Summer' : 'Winter')]['Proverbs'].forEach(function(e){
var elemDiv = document.createElement("div");
var elemPphrase = document.createElement("p");
var elemPinfo = document.createElement("p");
elemDiv.classList.add('hidden','proverb');
elemPphrase.appendChild(parser.parseFromString('<span>' + e['Content'] + '</span>', "text/html").body);
elemPinfo.appendChild(document.createTextNode(e['Author'] + (e['From'] === "" ? "" : " - " + e['From'])));
elemDiv.appendChild(elemPphrase);
elemDiv.appendChild(elemPinfo);
document.getElementById("proverbs").appendChild(elemDiv);
});
document.body.style.backgroundImage = "url('img/" + (hemi === 'N' ? "summer/summer" : "winter/winter") + Math.floor(Math.random() * (hemi === 'N' ? maxSummer : maxWinter) + 1) + ".jpg')";
} else if (today >= firstFall && today < firstWinter) {
Array.from(document.getElementsByClassName("season_name_span")).forEach(function(e){
e.innerHTML = (hemi === 'N' ? " Autumn" : " Spring");
});
document.getElementById("season_catchphrase").innerHTML = pvbs['Season'][(hemi === 'N' ? 'Fall' : 'Spring')]['Catchphrase'];
pvbs['Season'][(hemi === 'N' ? 'Fall' : 'Spring')]['Proverbs'].forEach(function(e){
var elemDiv = document.createElement("div");
var elemPphrase = document.createElement("p");
var elemPinfo = document.createElement("p");
elemDiv.classList.add('hidden','proverb');
elemPphrase.appendChild(parser.parseFromString('<span>' + e['Content'] + '</span>', "text/html").body);
elemPinfo.appendChild(document.createTextNode(e['Author'] + (e['From'] === "" ? "" : " - " + e['From'])));
elemDiv.appendChild(elemPphrase);
elemDiv.appendChild(elemPinfo);
document.getElementById("proverbs").appendChild(elemDiv);
});
document.body.style.backgroundImage = "url('img/" + (hemi === 'N' ? "fall/fall" : "spring/spring") + Math.floor(Math.random() * (hemi === 'N' ? maxFall : maxSpring) + 1) + ".jpg')";
} else if (today >= firstWinter || today < firstSpring) {
Array.from(document.getElementsByClassName("season_name_span")).forEach(function(e){
e.innerHTML = (hemi === 'N' ? " Winter" : " Summer");
});
document.getElementById("season_catchphrase").innerHTML = pvbs['Season'][(hemi === 'N' ? 'Winter' : 'Summer')]['Catchphrase'];
pvbs['Season'][(hemi === 'N' ? 'Winter' : 'Summer')]['Proverbs'].forEach(function(e){
var elemDiv = document.createElement("div");
var elemPphrase = document.createElement("p");
var elemPinfo = document.createElement("p");
elemDiv.classList.add('hidden','proverb');
elemPphrase.appendChild(parser.parseFromString('<span>' + e['Content'] + '</span>', "text/html").body);
elemPinfo.appendChild(document.createTextNode(e['Author'] + (e['From'] === "" ? "" : " - " + e['From'])));
elemDiv.appendChild(elemPphrase);
elemDiv.appendChild(elemPinfo);
document.getElementById("proverbs").appendChild(elemDiv);
});
document.body.style.backgroundImage = "url('img/" + (hemi === 'N' ? "winter/winter" : "summer/summer") + Math.floor(Math.random() * (hemi === 'N' ? maxWinter : maxSummer) + 1) + ".jpg')";
}
var proverbs = Array.from(document.getElementsByClassName("proverb"));
proverbs[curr].classList.toggle('hidden');
window.setInterval(nextProverb, 12000, proverbs);
}
function requestJson(url) {
// Create new promise with the Promise() constructor;
// This has as its argument a function
// with two parameters, resolve and reject
return new Promise(function(resolve, reject) {
// Standard XHR to load an image
var request = new XMLHttpRequest();
request.open('GET', url);
request.responseType = 'json';
// When the request loads, check whether it was successful
request.onload = function() {
if (request.status === 200) {
// If successful, resolve the promise by passing back the request response
resolve(request.response);
} else {
// If it fails, reject the promise with a error message
reject(new Error('Error: failed to retrieve the requested json;\nError code:' + request.statusText));
}
};
request.onerror = function() {
// Also deal with the case when the entire request fails to begin with
// This is probably a network error, so reject the promise with an appropriate message
reject(new Error('A network error has occured'));
};
request.send();
});
}
promise1 = requestJson('https://inf.alan736.ch/geoloc.php');
promise2 = requestJson('proverbs.json');
Promise.all([promise1, promise2]).then(function(values) {
var respAPI = (values[0]['latitude'] >= 0 ? 'N' : 'S');
var respJSON = values[1];
seasonalPageGen(respAPI,respJSON);
});
</script>
</html>