sign_up.ts 1013 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import './public-path';
  2. import axios from 'axios';
  3. import ready from '../mastodon/ready';
  4. async function checkConfirmation() {
  5. const response = await axios.get('/api/v1/emails/check_confirmation');
  6. if (response.data) {
  7. window.location.href = '/start';
  8. }
  9. }
  10. ready(() => {
  11. setInterval(() => {
  12. void checkConfirmation();
  13. }, 5000);
  14. document
  15. .querySelectorAll<HTMLButtonElement>('button.timer-button')
  16. .forEach((button) => {
  17. let counter = 30;
  18. const container = document.createElement('span');
  19. const updateCounter = () => {
  20. container.innerText = ` (${counter})`;
  21. };
  22. updateCounter();
  23. const countdown = setInterval(() => {
  24. counter--;
  25. if (counter === 0) {
  26. button.disabled = false;
  27. button.removeChild(container);
  28. clearInterval(countdown);
  29. } else {
  30. updateCounter();
  31. }
  32. }, 1000);
  33. button.appendChild(container);
  34. });
  35. }).catch((e: unknown) => {
  36. throw e;
  37. });