-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeath.js
335 lines (278 loc) · 8.18 KB
/
death.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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*
* If you're reading this, I'm probably dead.
* That's ok.
* This is the ancient language of JavaScript.
* This is what was used before everybody switched to the better thing.
* Please maintain this code, oh descendants of man.
*/
//create some elements
const galacticYearElem = document.createElement("p");
const milleniumElem = document.createElement("p");
const yearElem = document.createElement("p");
const dayElem = document.createElement("p");
const hourElem = document.createElement("p");
const minuteElem = document.createElement("p");
const secondElem = document.createElement("p");
//these are specially formatted to have commas
//because they were very big numbers
const bignum1 = document.createElement("span");
bignum1.setAttribute('class', 'bignum');
const bigtext1 = document.createElement("span");
const bignum2 = document.createElement("span");
bignum2.setAttribute('class', 'bignum');
const bigtext2 = document.createElement("span");
let galacticYear;
let millenium;
let year;
let day;
let hour;
let minute;
let second;
function formatTime(n) {
//big int is a JavaScript class that allows math with arbitrarily large integers
galacticYear = n / BigInt(24 * 3600 * 365.2425 * 1000 * 230000);
n %= BigInt(24 * 3600 * 365.2425 * 1000 * 230000);
millenium = n / BigInt(24 * 3600 * 365.2425 * 1000);
n %= BigInt(24 * 3600 * 365.2425 * 1000);
year = n / BigInt(24 * 3600 * 365.2425);
n %= BigInt(24 * 3600 * 365.2425);
day = n / BigInt(24 * 3600);
n %= BigInt(24 * 3600);
hour = n / BigInt(3600);
n %= BigInt(3600);
minute = n / BigInt(60) ;
n %= BigInt(60);
second = n;
//we use an 's' after words to indicate that there are more than 1 of something
let s = "s";
if (galacticYear == 1) {
s = "";
} else {
s = "s";
}
//invisible space between numbers, allowing the big number to "wrap"
let space = "<span class='space'> </span>";
//create a number and some text
let galacticYearText = document.createTextNode(galacticYear.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ", "));
let galacticYearText2 = document.createTextNode(" galactic year" + s + ", ");
//add the new text elements to another element
bignum1.appendChild(galacticYearText);
bignum1.innerHTML = bignum1.innerHTML.replace(/\s/g, space);
bigtext1.appendChild(galacticYearText2);
galacticYearElem.appendChild(bignum1);
galacticYearElem.appendChild(bigtext1);
if (millenium == 1) {
s = "ium";
} else {
s = "ia";
}
//same as above
let milleniumText = document.createTextNode(millenium.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ", "));
let milleniumText2 = document.createTextNode(" millen" +s+ ", ")
bignum2.appendChild(milleniumText);
bigtext2.appendChild(milleniumText2);
bignum2.innerHTML = bignum2.innerHTML.replace(/\s/g, space);
milleniumElem.appendChild(bignum2);
milleniumElem.appendChild(bigtext2);
if (year == 1) {
s = "";
} else {
s = "s";
}
//these don't need commas so they are simpler
let yearText = document.createTextNode(year + " year"+s+", ");
yearElem.appendChild(yearText);
if (day == 1) {
s = "";
} else {
s = "s";
}
let dayText = document.createTextNode(day + " day"+s+", ");
dayElem.appendChild(dayText);
if (hour == 1) {
s = "";
} else {
s = "s";
}
let hourText = document.createTextNode(hour + " hour"+s+", ");
hourElem.appendChild(hourText);
if (minute == 1) {
s = "";
} else {
s = "s";
}
let minuteText = document.createTextNode(minute + " minute"+s+", ")
minuteElem.appendChild(minuteText);
if (second == 1) {
s = "";
} else {
s = "s";
}
let secondText = document.createTextNode("and " + second + " second"+s+" until the end of the universe.");
secondElem.appendChild(secondText);
}
function resetAll(n) {
galacticYear = n / BigInt(24 * 3600 * 365.2425 * 1000 * 230000);
n %= BigInt(24 * 3600 * 365.2425 * 1000 * 230000);
millenium = n / BigInt(24 * 3600 * 365.2425 * 1000);
n %= BigInt(24 * 3600 * 365.2425 * 1000);
year = n / BigInt(24 * 3600 * 365.2425);
n %= BigInt(24 * 3600 * 365.2425);
day = n / BigInt(24 * 3600);
n %= BigInt(24 * 3600);
hour = n / BigInt(3600);
n %= BigInt(3600);
minute = n / BigInt(60) ;
n %= BigInt(60);
second = n;
if (second == 1) {
s = "";
} else {
s = "s";
}
if (minute == 1) {
m = "";
} else {
m = "s";
}
if (hour == 1) {
h = "";
} else {
h = "s";
}
if (day == 1) {
d = "";
} else {
d = "s";
}
if (year == 1) {
y = "";
} else {
y = "s";
}
if (millenium == 1) {
m2 = "ium";
} else {
m2 = "ia";
}
if (galacticYear == 1) {
g = "";
} else {
g = "s";
}
yearElem.innerHTML = year + " year"+y+", ";
dayElem.innerHTML = day + " day"+d+", ";
hourElem.innerHTML = hour + " hour"+h+", ";
minuteElem.innerHTML = minute + " minute"+m+", ";
secondElem.innerHTML = "and " + second + " second" + s + " until the end of the universe.";
let separator = ","+space;
bignum1.innerHTML = galacticYear.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator);
bigtext1.innerHTML = " galactic year"+g+", ";
bignum2.innerHTML = millenium.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator);
bigtext2.innerHTML = " millen"+m2+", ";
}
var count = 0;
var T = 17;
var t;
function decrementTimer() {
count ++ ;
if (count == T) {
//resync user system time every t seconds
//this is because, in our time, computers are not accurate
count = 0;
now = new Date();
now = Math.round(now.getTime() / 1000);
resetAll(endOfUniverse - BigInt(now));
clearInterval(t);
t=setInterval(decrementTimer,1000);
}
second--;
if (second == 1) {
s = "";
} else {
s = "s";
}
if (second <= -1) {
second = 59;
minute--;
if (minute == 1) {
m = "";
} else {
m = "s";
}
if (minute <= -1) {
minute = 59;
hour--;
if (hour == 1) {
h = "";
} else {
h = "s";
}
if (hour <= -1) {
day--;
if (day == 1) {
d = "";
} else {
d = "s";
}
if (day <= -1) {
year--;
if (year == 1) {
y = "";
} else {
y = "s";
}
if (year <= -1) {
millenium--;
if (millenium == 1) {
m2 = "ium";
} else {
m2 = "ia";
}
if (millenium <= -1) {
galacticYear--;
if (galacticYear == 1) {
g = "";
} else {
g = "s";
}
bignum1.innerHTML = galacticYear;
bigtext1.innerHTML = " galactic year"+g+", ";
}
bignum2.innerHTML = millenium;
bigtext2.innerHTML = " millen"+m2+", ";
}
yearElem.innerHTML = year + " year"+y+", ";
}
dayElem.innerHTML = day + " day"+d+", ";
}
hourElem.innerHTML = hour + " hour"+h+", ";
}
minuteElem.innerHTML = minute + " minute"+m+", ";
}
secondElem.innerHTML = "and " + second + " second" + s + " until the end of the universe.";
}
//this will take a 41 bit time from the client computer that we
//will shave the milliseconds off of because we dont need them.
//TODO: this will break in 2038. plz replace with whatever ya'll are using then
var now = new Date();
now = Math.round(now.getTime() / 1000);
let endOfUniverse = BigInt(2)**BigInt(512)-BigInt(1)
let nowElem = document.getElementById("now");
formatedTime = formatTime(endOfUniverse - BigInt(now));
//Create some text that just has the word "approximately"
let approx = document.createElement("h3");
let approxText = document.createTextNode("Approximately ")
approx.appendChild(approxText);
//add all the elements to an element in the page
nowElem.appendChild(approx);
nowElem.appendChild(galacticYearElem);
nowElem.appendChild(milleniumElem);
nowElem.appendChild(yearElem);
nowElem.appendChild(dayElem);
nowElem.appendChild(hourElem);
nowElem.appendChild(minuteElem);
nowElem.appendChild(secondElem);
//every second update the time we have left
var t=setInterval(decrementTimer,1000);
//That's all!