2022-05-27 16:58:39 +00:00
|
|
|
|
const relative_to_local = new Intl.RelativeTimeFormat("ru", {numeric: 'auto', style: 'long'});
|
2020-11-30 19:15:49 +00:00
|
|
|
|
function getTimeRemaining(endtime) {
|
|
|
|
|
var t = Date.parse(endtime) - Date.now();
|
|
|
|
|
var mseconds = t % 1000;
|
|
|
|
|
var seconds1_100 = Math.floor((t / 10) % 1000);
|
|
|
|
|
var seconds = Math.floor((t / 1000) % 60);
|
|
|
|
|
var minutes = Math.floor((t / 1000 / 60) % 60);
|
|
|
|
|
var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
|
|
|
|
|
var days = Math.floor(t / (1000 * 60 * 60 * 24));
|
|
|
|
|
return {
|
|
|
|
|
'total': t,
|
|
|
|
|
'days': days,
|
|
|
|
|
'hours': hours,
|
|
|
|
|
'minutes': minutes,
|
|
|
|
|
'seconds': seconds,
|
|
|
|
|
'seconds1_100': seconds1_100,
|
|
|
|
|
'mseconds': mseconds
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-12-22 19:27:51 +00:00
|
|
|
|
let phases = ["Переходная (с ночи на день)", "Дневная", "Переходная (со дня на ночь)", "Ночная"]
|
2020-11-30 19:15:49 +00:00
|
|
|
|
function changeBackgroundColor() {
|
2021-08-11 18:56:11 +00:00
|
|
|
|
let t = new Date();
|
2021-08-12 09:03:56 +00:00
|
|
|
|
let local_t = t.getTime() - t.getTimezoneOffset()*60000 - 180*60000;
|
2021-08-11 18:56:11 +00:00
|
|
|
|
let color_var = (local_t % 86400000 > 43200000) ? 1-(local_t % 21600000 / 21600000) : local_t % 21600000 / 21600000
|
|
|
|
|
let color_phase = local_t % 86400000 / 21600000
|
2021-08-12 17:38:28 +00:00
|
|
|
|
let colors = [[112,38,112], [13,117,248]];
|
2021-08-11 18:56:11 +00:00
|
|
|
|
switch (Math.trunc(color_phase)) {
|
|
|
|
|
case 0:
|
|
|
|
|
case 2:
|
2021-08-12 17:55:53 +00:00
|
|
|
|
currect = [colors[0][0]-Math.abs(colors[0][0], colors[1][0])*color_var, colors[0][1]+Math.abs(colors[0][1], colors[1][1])*color_var, colors[0][2]+Math.abs(colors[0][2], colors[1][2])*color_var];
|
2021-08-11 18:56:11 +00:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
currect = colors[1]
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
currect = colors[0]
|
2020-11-30 19:15:49 +00:00
|
|
|
|
}
|
|
|
|
|
document.getElementsByTagName("body")[0].style.backgroundColor = "#"+("0"+Math.round(currect[0]).toString(16)).slice(-2)+("0"+Math.round(currect[1]).toString(16)).slice(-2)+("0"+Math.round(currect[2]).toString(16)).slice(-2);
|
2021-12-22 19:27:51 +00:00
|
|
|
|
var num_f = 2;
|
|
|
|
|
document.getElementById("color").innerHTML = "R:" + currect[0].toFixed(num_f) + "; G:" + currect[1].toFixed(num_f) + "; B:" + currect[2].toFixed(num_f);
|
|
|
|
|
document.getElementById("phase").innerHTML = phases[Math.trunc(color_phase)] + ", " + ((color_phase % 1)*100).toFixed(num_f)+"%"
|
2020-11-30 19:15:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initializeClock(endtime) {
|
|
|
|
|
var num1 = document.getElementById('num1');
|
|
|
|
|
var num2 = document.getElementById('num2');
|
2021-08-15 19:33:18 +00:00
|
|
|
|
var num3 = document.getElementById('num3');
|
|
|
|
|
var dots1 = document.getElementById('separator1');
|
|
|
|
|
var dots2 = document.getElementById('separator2');
|
2020-11-30 19:15:49 +00:00
|
|
|
|
var debug1 = document.getElementById('endtime');
|
|
|
|
|
var debug2 = document.getElementById('left');
|
|
|
|
|
var debug3 = document.getElementById('fulltimer');
|
2021-09-22 10:53:34 +00:00
|
|
|
|
var time_to = new Date(endtime)
|
2020-11-30 19:15:49 +00:00
|
|
|
|
var updateTime = 1000 / 60;
|
|
|
|
|
|
|
|
|
|
function updateClock() {
|
|
|
|
|
var t = getTimeRemaining(endtime);
|
2021-08-15 19:33:18 +00:00
|
|
|
|
if (t.days > 0) {
|
2021-09-22 10:53:34 +00:00
|
|
|
|
num1.innerHTML = t.days;
|
2021-08-15 19:33:18 +00:00
|
|
|
|
dots1.innerHTML = "д.   ";
|
|
|
|
|
dots1.style.fontSize = "3rem";
|
|
|
|
|
dots1.style.width = dots2.style.width;
|
2020-11-30 19:15:49 +00:00
|
|
|
|
num2.innerHTML = ('0' + t.hours).slice(-2);
|
2021-08-15 19:33:18 +00:00
|
|
|
|
num3.innerHTML = ('0' + t.minutes).slice(-2);
|
2022-05-27 16:58:39 +00:00
|
|
|
|
document.title = "НГ " + relative_to_local.format(t.days, "day");
|
2020-11-30 19:15:49 +00:00
|
|
|
|
}
|
|
|
|
|
else if (t.hours > 0) {
|
|
|
|
|
num1.innerHTML = ('0' + t.hours).slice(-2);
|
2021-08-15 19:33:18 +00:00
|
|
|
|
dots1.innerHTML = ":";
|
|
|
|
|
dots1.style.fontSize = "1em";
|
2020-11-30 19:15:49 +00:00
|
|
|
|
num2.innerHTML = ('0' + t.minutes).slice(-2);
|
2021-08-15 19:33:18 +00:00
|
|
|
|
num3.innerHTML = ('0' + t.seconds).slice(-2);
|
2022-05-27 16:58:39 +00:00
|
|
|
|
document.title = "НГ " + relative_to_local.format(t.hours, "hour");
|
2020-11-30 19:15:49 +00:00
|
|
|
|
}
|
2021-08-15 19:33:18 +00:00
|
|
|
|
else if (t.total > 0) {
|
2020-11-30 19:15:49 +00:00
|
|
|
|
num1.innerHTML = ('0' + t.minutes).slice(-2);
|
|
|
|
|
num2.innerHTML = ('0' + t.seconds).slice(-2);
|
2021-08-15 19:33:18 +00:00
|
|
|
|
num3.innerHTML = ('0' + t.seconds1_100).slice(-2);
|
|
|
|
|
dots2.innerHTML = ".";
|
2022-05-27 16:58:39 +00:00
|
|
|
|
document.title = "НГ " + ((t.total <= 60000) ? relative_to_local.format(t.seconds, "second") : relative_to_local.format(t.minutes, "minute"));
|
2020-11-30 19:15:49 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
num1.innerHTML = "00";
|
|
|
|
|
num2.innerHTML = "00";
|
2021-08-15 19:33:18 +00:00
|
|
|
|
num3.innerHTML = "00";
|
2020-11-30 19:15:49 +00:00
|
|
|
|
clearInterval(timeinterval);
|
|
|
|
|
document.title = "С новым годом!";
|
2021-09-21 16:25:31 +00:00
|
|
|
|
document.getElementsByClassName("countdown-title")[0].innerHTML = "C новым годом!!!\nСчасливого " + future_year + " года!";
|
2021-08-15 19:33:18 +00:00
|
|
|
|
setTimeout(function() {
|
|
|
|
|
$('body').fireworks();
|
|
|
|
|
});
|
2020-11-30 19:15:49 +00:00
|
|
|
|
};
|
2021-08-15 19:33:18 +00:00
|
|
|
|
dots1.style.color = ((t.seconds % 2) || (t.total <= 3600000) || (t.days > 0)) ? "#fff":"#fff0";
|
|
|
|
|
dots2.style.color = ((t.seconds % 2) || (t.total <= 3600000)) ? "#fff":"#fff0";
|
2020-11-30 19:15:49 +00:00
|
|
|
|
debug2.innerHTML = t.total.toLocaleString('ru');
|
|
|
|
|
debug3.innerHTML = t.days + ':' + ('0' + t.hours).slice(-2) + ':' + ('0' + t.minutes).slice(-2) + ':' + ('0' + t.seconds).slice(-2) + '.' + ('00' + t.mseconds).slice(-3);
|
|
|
|
|
}
|
2021-09-22 10:53:34 +00:00
|
|
|
|
debug1.innerHTML = time_to.toLocaleString();
|
2020-11-30 19:15:49 +00:00
|
|
|
|
updateClock();
|
|
|
|
|
var timeinterval = setInterval(updateClock, updateTime);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-11 18:56:11 +00:00
|
|
|
|
let d_for_setting = new Date();
|
|
|
|
|
let future_year = (d_for_setting.getMonth() == 0 && d_for_setting.getDate() < 7) ? d_for_setting.getFullYear() : d_for_setting.getFullYear() + 1
|
2020-11-30 19:15:49 +00:00
|
|
|
|
document.getElementById("future_year").innerHTML = future_year;
|
|
|
|
|
initializeClock("Jan 01 " + future_year + " 00:00:00");
|
2022-05-27 16:58:39 +00:00
|
|
|
|
//initializeClock("Apr 27 2022 23:24:00");
|
2021-08-15 19:33:18 +00:00
|
|
|
|
setInterval(changeBackgroundColor, 1000/60);
|