-
Notifications
You must be signed in to change notification settings - Fork 1
/
more.js
99 lines (93 loc) · 3.59 KB
/
more.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
'use strict';
(function () {
window.onload = function () {
var time = parseTime('time');
log(time);
if (time === null) {
time = new Date();
}
document.getElementById('time').value = toLocalIso(time);
print(time);
document.getElementById('time').oninput = function () {
var input = new Date(document.getElementById('time').value);
if (input.toString() !== 'Invalid Date') {
print(input);
}
};
};
function print(time) {
var link = 'aqoleg.github.io/time?time=' + toLocalIso(time);
document.getElementById('index').href = 'https://' + link;
document.getElementById('index').innerHTML = link;
document.getElementById('fullMoon').innerHTML = toLocalIso(Moon.full(time, false));
document.getElementById('newMoon').innerHTML = toLocalIso(Moon.new(time, false));
document.getElementById('firstMoon').innerHTML = toLocalIso(Moon.firstQuarter(time, false));
document.getElementById('lastMoon').innerHTML = toLocalIso(Moon.lastQuarter(time, false));
var year = time.getUTCFullYear();
var equinox = Equinox.june(year);
if (equinox.getTime() < time.getTime()) {
equinox = Equinox.june(year + 1);
}
document.getElementById('june').innerHTML = toLocalIso(equinox);
equinox = Equinox.december(year);
if (equinox.getTime() < time.getTime()) {
equinox = Equinox.december(year + 1);
}
document.getElementById('december').innerHTML = toLocalIso(equinox);
equinox = Equinox.march(year);
if (equinox.getTime() < time.getTime()) {
equinox = Equinox.march(year + 1);
}
document.getElementById('march').innerHTML = toLocalIso(equinox);
equinox = Equinox.september(year);
if (equinox.getTime() < time.getTime()) {
equinox = Equinox.september(year + 1);
}
document.getElementById('september').innerHTML = toLocalIso(equinox);
document.getElementById('more').href = '?time=' + toLocalIso(time);
}
function log(time) {
var user = 'aqoleg.github.io/time/more';
if (time) {
user += '#' + time.toISOString().substr(0, 10) + 'Z';
}
var language = null;
if (typeof navigator.language === 'string') {
language = navigator.language.substr(0, 2);
}
fetch('https://aqoleg.com/log', {
method: 'POST',
body: JSON.stringify({
user: user,
language: language,
timeZone: new Date().getTimezoneOffset() / (-60)
})
}).catch(console.error);
}
function parseTime(query) {
var startIndex = window.location.search.indexOf(query + '=');
if (startIndex < 0) {
return null;
}
startIndex = startIndex + query.length + 1;
var stopIndex = window.location.search.indexOf('&', startIndex);
var time;
if (stopIndex < 0) {
time = window.location.search.substring(startIndex);
} else {
time = window.location.search.substring(startIndex, stopIndex);
}
if (Number(time) > 0) {
time = new Date(time * 1000);
} else {
time = new Date(time);
}
if (time.toString() === 'Invalid Date') {
return null;
}
return time;
}
function toLocalIso(date) {
return new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString().substr(0, 19);
}
})();