-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
55 lines (48 loc) · 1.75 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
console.log();
const now = new Date();
// https://stackoverflow.com/questions/2998784/how-to-output-numbers-with-leading-zeros-in-javascript
function pad(num, size) {
num = num.toString();
while (num.length < size) num = "0" + num;
return num;
}
// https://stackoverflow.com/questions/29816872/how-can-i-convert-milliseconds-to-hhmmss-format-using-javascript
function msToHMS(ms) {
let seconds = parseInt(ms / 1000);
const hours = parseInt(seconds / 3600);
seconds = seconds % 3600;
const minutes = parseInt(seconds / 60);
seconds = seconds % 60;
return (pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2));
}
// https://stackoverflow.com/questions/30922008/calculate-percentage-javascript
function percentage(partialValue, totalValue) {
return (100 * partialValue) / totalValue;
}
function itsNovember() {
const innerNow = new Date();
if (innerNow.getMonth() == 10) {
return true;
} else return false;
}
const nstart = new Date("11/01/" + now.getFullYear() + " 00:00:00").getTime();
const dstart = new Date("12/01/" + now.getFullYear() + " 00:00:00").getTime();
const mlenght = dstart - nstart;
function NNN() {
const now_ms = Date.now();
const until = (dstart - now_ms);
const until_now = (dstart - nstart) - until;
if (itsNovember()) {
$('.nnn').show();
$('.nnn_stats').show();
$('.until').html(msToHMS(until));
$('.stats_hours').html(msToHMS(until_now));
$('.stats_percentage').html(percentage(until_now, mlenght).toFixed(5) + "%");
$('.non_nnn').hide();
setTimeout(NNN, 250);
} else {
$('.nnn').hide();
$('.non_nnn').show();
setTimeout(NNN, 250);
}
};