Problem-2038-site/script.js

58 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-06-27 19:16:43 +00:00
const maxtimestamp = 2147483647;
var readable_timer_mode = 0;
2020-07-03 12:53:13 +00:00
var msec_display = true;
2020-06-27 19:16:43 +00:00
function ReadableTimerSwitcher(){
readable_timer_mode++
2020-07-03 12:53:13 +00:00
if(readable_timer_mode > 2){readable_timer_mode = 0}
}
function msecDisplaySwitcher(){
if(msec_display){
msec_display = false
$("#time-left-msec").css("display", "none");
}else{
msec_display = true
$("#time-left-msec").css("display", "unset");
}
2020-06-27 19:16:43 +00:00
}
2020-06-26 11:52:22 +00:00
function Cycle() {
var timestamp = Date.now() / 1000,
left = maxtimestamp - timestamp,
tmsec = Math.floor(left * 1000) % 1000,
2020-06-27 19:16:43 +00:00
t = Math.floor(left);
2020-06-26 11:52:22 +00:00
$("#time-left").html(t.toLocaleString('ru'));
$("#time-left-msec").html("." + ('00' + tmsec).slice(-3));
$("#prog").val(timestamp);
$("#timestamp").html(Math.trunc(timestamp).toLocaleString('ru'));
2020-07-03 12:53:13 +00:00
if (left < 60 && readable_timer_mode != 2) { $("#time-left-readable").css("display", "none") }
2020-06-26 11:52:22 +00:00
if (left <= 0) {
clearInterval(c);
$("#time-left").html("0");
$("#time-left-msec").html(".000");
$("#title").html("С͓̪̩̳͕͍̄ͮͤ̚̚м̦͎͉̝̋̄е̥͕̫̫̱̱͓̞̾р̞̤̰͖̤̟̫͓̏̍͒ͣ͐͂̚ͅт̗̥̲̩̣̯̹̅ͅь̙͍̟̟̮̩̦̹ͩͤ");
}
2020-06-27 19:16:43 +00:00
switch (readable_timer_mode){
case 0:
var tsec = Math.floor(left % 60),
tmin = Math.floor(left / 60) % 60,
thour = Math.floor(left / 60 / 60) % 24,
tday = Math.floor(left / 60 / 60 / 24);
$("#time-left-readable").html("(" + tday + ":" + ("0" + thour).slice(-2) + ":" + ("0" + tmin).slice(-2) + ":" + ("0" + tsec).slice(-2) + ")");
break;
case 1:
var tsec = Math.floor(left % 60),
tmin = Math.floor(left / 60) % 60,
thour = Math.floor(left / 60 / 60) % 24,
tday = Math.floor(left / 60 / 60 / 24) % 365,
tyear = Math.floor(left / 60 / 60 / 24 / 365);
$("#time-left-readable").html("(" + tyear + " л. " + tday + " дн. " + ("0" + thour).slice(-2) + ":" + ("0" + tmin).slice(-2) + ":" + ("0" + tsec).slice(-2) + ")");
break;
2020-07-03 12:53:13 +00:00
case 2:
var precentage = (timestamp/maxtimestamp)*100;
$("#time-left-readable").html(Math.trunc(timestamp).toLocaleString('ru')+" / "+maxtimestamp.toLocaleString('ru')+" ("+precentage.toFixed(8)+"%)");
break;
2020-06-27 19:16:43 +00:00
}
2020-06-26 11:52:22 +00:00
}
var c = setInterval(Cycle, 1000 / 60);