indications.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Utils informations
  2. const KEYCODE_Q = 81
  3. const KEYCODE_ENTER = 13
  4. const KEYCODE_LEFT_ARROW = 37
  5. const KEYCODE_RIGHT_ARROW = 39
  6. urlParams = new URLSearchParams(window.location.search)
  7. var scene = urlParams.get('scene')
  8. const expe = urlParams.get('expe')
  9. var example = urlParams.get('example')
  10. if (example == null || example == ''){
  11. example = 0
  12. }
  13. if (scene === null || scene === ''){
  14. scene = document.getElementsByName('scene_name')[0].value
  15. }
  16. const checkKey = e => {
  17. if (e.keyCode === KEYCODE_Q) {
  18. // `q` to quit expe
  19. console.log('`q` key is pressed')
  20. window.location = ''
  21. }
  22. else if (e.keyCode === KEYCODE_ENTER) {
  23. // right arrow
  24. const experimentId = document.getElementsByName('experimentId')[0].value
  25. const params = `?scene=${scene}&expe=${expe}&experimentId=${experimentId}&iteration=0`
  26. console.log(expeUrl + params)
  27. window.location = expeUrl + params
  28. }
  29. else if (e.keyCode === KEYCODE_LEFT_ARROW || e.keyCode === KEYCODE_RIGHT_ARROW) {
  30. // increment number of example
  31. example = parseInt(example) + 1
  32. console.log("I'm here")
  33. // construct url with params for experiments
  34. const params = `?scene=${scene}&expe=${expe}&example=${example}`
  35. window.location = indicationsUrl + params
  36. }
  37. }
  38. // implement `key` events
  39. document.addEventListener('keydown', checkKey)