index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Import Bootstrap
  2. import 'bootstrap'
  3. import 'bootstrap/dist/css/bootstrap.min.css'
  4. // Import own css
  5. import '../css/index.css'
  6. // Import SimpleMDE
  7. import SimpleMDE from 'simplemde'
  8. import 'simplemde/dist/simplemde.min.css'
  9. if (document.querySelector('textarea') != null) {
  10. new SimpleMDE()
  11. }
  12. // Javascript
  13. function countdown() {
  14. let element = document.querySelector(".countdown")
  15. let date = element.getAttribute('date');
  16. let days, hours, minutes, seconds;
  17. let endDate = new Date(date).getTime();
  18. if (isNaN(endDate)) {
  19. return;
  20. }
  21. let startDate = new Date().getTime();
  22. if (endDate > startDate) {
  23. calculate()
  24. setInterval(calculate, 1000);
  25. }
  26. function calculate() {
  27. let startDate = new Date().getTime();
  28. let timeRemaining = parseInt((endDate - startDate) / 1000);
  29. if (timeRemaining >= 0) {
  30. hours = parseInt(timeRemaining / 3600);
  31. timeRemaining = (timeRemaining % 3600);
  32. minutes = parseInt(timeRemaining / 60);
  33. timeRemaining = (timeRemaining % 60);
  34. seconds = parseInt(timeRemaining);
  35. document.querySelector(".countdown .hours").innerHTML = ("0" + hours).slice(-2);
  36. document.querySelector(".countdown .minutes").innerHTML = ("0" + minutes).slice(-2);
  37. document.querySelector(".countdown .seconds").innerHTML = ("0" + seconds).slice(-2);
  38. } else {
  39. window.location.reload(false);
  40. }
  41. }
  42. }
  43. window.onload = function () {
  44. if (document.querySelector('.countdown') != null) {
  45. countdown();
  46. }
  47. }