index.html 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <html>
  2. <head>
  3. <title> GrowCam </title>
  4. <script>
  5. var i = 0;
  6. var pictures = [];
  7. var interval = null;
  8. function reload() {
  9. if (i >= pictures.length) i = 0;
  10. document.getElementById('picture').src = '/pictures/' + pictures[i++];
  11. document.getElementById('currentPictureLabel').innerText = pictures[i++];
  12. }
  13. function getPictureList() {
  14. var req = new XMLHttpRequest();
  15. req.addEventListener('load', function () {
  16. pictures = JSON.parse(this.responseText).pictures;
  17. document.getElementById('pictureCount').innerText = pictures.length;
  18. });
  19. req.open('GET', '/pictures');
  20. req.send();
  21. }
  22. function pausePlay() {
  23. if (interval) {
  24. clearInterval(interval);
  25. interval = null;
  26. } else {
  27. interval = setInterval(reload, 100);
  28. }
  29. }
  30. window.onload = function () {
  31. getPictureList();
  32. pausePlay();
  33. // setInterval(reload, 100);
  34. };
  35. </script>
  36. </head>
  37. <body>
  38. <p>Pictures available: <span id="pictureCount"></span> showing <span id="currentPictureLabel"></span></p>
  39. <img id="picture" width="800" height="600" onclick="pausePlay()"/>
  40. </body>
  41. </html>