forked from NiktarioN/autoweb-timer-getcourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoweb-timer-getcourse.txt
99 lines (87 loc) · 2.57 KB
/
autoweb-timer-getcourse.txt
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
<div class="timer">
<div class="timer-numbers" id="timer">
<span class="hours">00</span>
<span>:</span>
<span class="minutes">00</span>
<span>:</span>
<span class="seconds">00</span>
</div>
</div>
<style>
.timer {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.timer-numbers {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
padding: 0px 20px;
font-size: 72px;
background: rgba(0, 0, 0, 0.05);
color: #d07684;
font-family: 'Roboto', sans-serif;
font-weight: 700;
}
@media only screen and (max-width : 768px) {
.timer-numbers {
font-size: 60px;
}
}
@media only screen and (max-width : 380px) {
.timer-numbers {
width: 100%;
font-size: 48px;
}
}
</style>
<script>
window.addEventListener('DOMContentLoaded', function () {
let timer = document.querySelector('#timer'),
diffHours = timer.querySelector('.hours'),
diffMinutes = timer.querySelector('.minutes'),
diffSeconds = timer.querySelector('.seconds');
function showTime(userHours = 19, userMinutes = 30, userUrl = 'https://getcourse.ru/') {
// Получаем время пользователя
let d = new Date(),
// Разница МСК часового пояса с UTC
mskUtcHours = -3,
// Разница часового пояса пользователя, делим на 60, т.к. нам нужны часы
viewerTimeZone = d.getTimezoneOffset() / 60,
// Разница часовых поясов пользователя и МСК по времени которого начинается вебинар
diffUtcTime = mskUtcHours - (viewerTimeZone),
hours = d.getHours() - diffUtcTime,
minutes = d.getMinutes(),
seconds = d.getSeconds();
if (hours == userHours && (minutes - userMinutes < 0)) {
location.href = userUrl;
}
if (hours < userHours) {
diffHours.textContent = setZeroBeforeDate(userHours - hours - 1);
} else {
diffHours.textContent = setZeroBeforeDate(((23 - d.getHours()) + userHours));
}
diffMinutes.textContent = setZeroBeforeDate(59 - minutes);
diffSeconds.textContent = setZeroBeforeDate(59 - seconds);
}
setInterval(showTime, 1000, 19, 30, 'https://getcourse.ru/');
function setZeroBeforeDate(item) {
if (item < 10) {
item = "0" + item;
} else {
item = item;
}
return item;
}
});
</script>