~cytrogen/masto-fe

ref: d640c0356ebda19e1940c8c100613881243dc4b2 masto-fe/app/javascript/packs/sign_up.js -rw-r--r-- 897 bytes
d640c035 — Cytrogen Fix merged PR bugs and rewrite reduced-motion to pure CSS 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 "./public-path";
import axios from "axios";

import ready from "../mastodon/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);
  });
});