~cytrogen/masto-fe

ref: dc35e2d7569a293bbda92ee3ecba8d2d4e6a7b64 masto-fe/app/javascript/flavours/glitch/packs/sign_up.js -rw-r--r-- 905 bytes
dc35e2d7 — Cytrogen Rename .scss → .css and remove sass dependency (Phase 9-10) 15 days ago
                                                                                
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
import "packs/public-path";
import axios from "axios";

import ready from "flavours/glitch/ready";

ready(() => {
  setInterval(() => {
    axios.get("/api/v1/emails/check_confirmation").then((response) => {
      if (response.data) {
        window.location = "/start";
      }
    }).catch(error => {
      console.error(error);
    });
  }, 5000);

  document.querySelectorAll(".timer-button").forEach(button => {
    let counter = 30;

    const container = document.createElement("span");

    const updateCounter = () => {
      container.innerText = ` (${counter})`;
    };

    updateCounter();

    const countdown = setInterval(() => {
      counter--;

      if (counter === 0) {
        button.disabled = false;
        button.removeChild(container);
        clearInterval(countdown);
      } else {
        updateCounter();
      }
    }, 1000);

    button.appendChild(container);
  });
});