~cytrogen/masto-fe

ref: 97f3d7b66280f5366a63bb0ad3df47e869530f2d masto-fe/app/javascript/packs/sign_up.js -rw-r--r-- 897 bytes
97f3d7b6 — Jeong Arm Fix Version metadata have trailing dot (#2403) 2 years 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);
  });
});