Readable timer clickable now

This commit is contained in:
dan63047 2020-06-27 22:16:43 +03:00
parent cd19d83247
commit c5e78a2dd5
3 changed files with 29 additions and 8 deletions

View File

@ -13,7 +13,7 @@
<body> <body>
<h1 id="title">До смерти 32-битных систем осталось</h1> <h1 id="title">До смерти 32-битных систем осталось</h1>
<div style="text-align: center;"><span id="time-left"></span><span id="time-left-msec"></span></div> <div style="text-align: center;"><span id="time-left"></span><span id="time-left-msec"></span></div>
<p id="time-left-readable"></p> <p id="time-left-readable" onclick="ReadableTimerSwitcher()"></p>
<progress id="prog" max="2147483647"></progress> <progress id="prog" max="2147483647"></progress>
<div id="decsription"> <div id="decsription">
<h3>О чём этот сайт?</h3> <h3>О чём этот сайт?</h3>

View File

@ -1,23 +1,43 @@
const maxtimestamp = 2147483647;
var readable_timer_mode = 0;
function ReadableTimerSwitcher(){
readable_timer_mode++
if(readable_timer_mode > 1){readable_timer_mode = 0}
}
function Cycle() { function Cycle() {
var timestamp = Date.now() / 1000, var timestamp = Date.now() / 1000,
maxtimestamp = 2147483647,
left = maxtimestamp - timestamp, left = maxtimestamp - timestamp,
t = Math.floor(left),
tmsec = Math.floor(left * 1000) % 1000, tmsec = Math.floor(left * 1000) % 1000,
tsec = Math.floor(left % 60), t = Math.floor(left);
tmin = Math.floor(left / 60) % 60,
thour = Math.floor(left / 60 / 60) % 24,
tday = Math.floor(left / 60 / 60 / 24);
$("#time-left").html(t.toLocaleString('ru')); $("#time-left").html(t.toLocaleString('ru'));
$("#time-left-msec").html("." + ('00' + tmsec).slice(-3)); $("#time-left-msec").html("." + ('00' + tmsec).slice(-3));
$("#prog").val(timestamp); $("#prog").val(timestamp);
$("#timestamp").html(Math.trunc(timestamp).toLocaleString('ru')); $("#timestamp").html(Math.trunc(timestamp).toLocaleString('ru'));
if (left > 60) { $("#time-left-readable").html("(" + tday + ":" + ("0" + thour).slice(-2) + ":" + ("0" + tmin).slice(-2) + ":" + ("0" + tsec).slice(-2) + ")") } else { $("#time-left-readable").css("display", "none") } if (left < 60) { $("#time-left-readable").css("display", "none") }
if (left <= 0) { if (left <= 0) {
clearInterval(c); clearInterval(c);
$("#time-left").html("0"); $("#time-left").html("0");
$("#time-left-msec").html(".000"); $("#time-left-msec").html(".000");
$("#title").html("С͓̪̩̳͕͍̄ͮͤ̚̚м̦͎͉̝̋̄е̥͕̫̫̱̱͓̞̾р̞̤̰͖̤̟̫͓̏̍͒ͣ͐͂̚ͅт̗̥̲̩̣̯̹̅ͅь̙͍̟̟̮̩̦̹ͩͤ"); $("#title").html("С͓̪̩̳͕͍̄ͮͤ̚̚м̦͎͉̝̋̄е̥͕̫̫̱̱͓̞̾р̞̤̰͖̤̟̫͓̏̍͒ͣ͐͂̚ͅт̗̥̲̩̣̯̹̅ͅь̙͍̟̟̮̩̦̹ͩͤ");
} }
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;
}
} }
var c = setInterval(Cycle, 1000 / 60); var c = setInterval(Cycle, 1000 / 60);

View File

@ -11,6 +11,7 @@ body{
} }
#time-left-readable{ #time-left-readable{
text-align: center; text-align: center;
cursor: pointer;
} }
#title{ #title{
text-align: center; text-align: center;