AkinoKaze commited on
Commit
6974fc5
·
verified ·
1 Parent(s): 0dac416

Upload Timer.js

Browse files
Files changed (1) hide show
  1. Timer.js +64 -0
Timer.js ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function colab_timer() {
2
+ console.log("таймер колаба");
3
+ let colab_inprogress = `<svg ...></svg>`; // ваш SVG-код
4
+
5
+ let startTime;
6
+ let timeout;
7
+
8
+ function updateTimer(el) {
9
+ const a = (i) => (i < 10 ? "0" + i : i);
10
+ const b = (x) => Math.floor(x);
11
+ let c = b(Date.now() / 1000) - startTime;
12
+ let h = a(b(c / 3600));
13
+ let m = a(b((c / 60) % 60));
14
+ let s = a(b(c % 60));
15
+
16
+ if (c > 298 && c < 315) {
17
+ el.innerText = "Обычно в это время вылазит капча, проверь вкладку колаба (" + h + ":" + m + ":" + s + ")";
18
+ } else {
19
+ el.innerText = h + ":" + m + ":" + s;
20
+ }
21
+
22
+ if (c % 30 == 0) {
23
+ refreshTimer(el, true);
24
+ return;
25
+ }
26
+ timeout = setTimeout(() => updateTimer(el), 1000);
27
+ }
28
+
29
+ const refreshTimer = (timerEl, notext = false) => {
30
+ if (timeout) {
31
+ clearTimeout(timeout);
32
+ timeout = null;
33
+ }
34
+ if (!notext) {
35
+ timerEl.innerText = "подключение...";
36
+ timerEl.style.color = "#ff9f00";
37
+ }
38
+
39
+ fetch("file=static/launch.txt", { cache: "no-store" })
40
+ .then((response) => {
41
+ if (response.status == 404) {
42
+ timerEl.innerText = "колаб выключился!";
43
+ timerEl.style.color = "red";
44
+
45
+ const audioSrc = "/content/a1111/timer.mp3"; // путь к аудиофайлу
46
+ const audio = document.createElement("audio");
47
+ audio.src = audioSrc;
48
+ audio.style.display = "none";
49
+ document.body.appendChild(audio);
50
+ audio.play().catch((error) => console.log("звук не удалось воспроизвести", error));
51
+
52
+ return;
53
+ } else if (response.status != 404) {
54
+ img.innerHTML = colab_inprogress;
55
+ timerEl.style.color = "#ff9f00";
56
+ }
57
+
58
+ response.text().then((text) => {
59
+ startTime = parseInt(text);
60
+ updateTimer(timerEl);
61
+ });
62
+ })
63
+ .catch((err) => {
64
+ console.log