You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

  1. $(function () {
  2. $('[data-toggle="tooltip"]').tooltip();
  3. var url = $("#pitch-url").text();
  4. var lastPing = null;
  5. var lastPingHuman = null;
  6. $("#run-it").click(function() {
  7. $.get(url);
  8. });
  9. function checkLastPing() {
  10. $.getJSON("/welcome/timer/", function(data) {
  11. if (data.last_ping != lastPing) {
  12. lastPing = data.last_ping;
  13. $("#timer").data("timer", data.timer);
  14. }
  15. if (data.last_ping_human.indexOf("seconds ago") > 0)
  16. data.last_ping_human = "seconds ago";
  17. if (data.last_ping_human != lastPingHuman) {
  18. lastPingHuman = data.last_ping_human;
  19. $("#last-ping").text(lastPingHuman);
  20. }
  21. });
  22. }
  23. function updateTimer() {
  24. var timer = parseInt($("#timer").data("timer"));
  25. if (timer == 0)
  26. return;
  27. var s = timer % 60;
  28. var m = parseInt(timer / 60) % 60;
  29. var h = parseInt(timer / 3600);
  30. $("#timer").text(h + "h " + m + "m " + s + "s");
  31. $("#timer").data("timer", timer - 1);
  32. }
  33. setInterval(checkLastPing, 3000);
  34. setInterval(updateTimer, 1000);
  35. });