indications.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. const 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. const checkKey = e => {
  14. if (e.keyCode === KEYCODE_Q) {
  15. // `q` to quit expe
  16. console.log('`q` key is pressed')
  17. window.location = ''
  18. }
  19. else if (e.keyCode === KEYCODE_ENTER) {
  20. // right arrow
  21. const experimentId = document.getElementsByName('experimentId')[0].value
  22. const params = `?scene=${scene}&expe=${expe}&experimentId=${experimentId}&iteration=0`
  23. console.log(expeUrl + params)
  24. window.location = expeUrl + params
  25. }
  26. else if (e.keyCode === KEYCODE_LEFT_ARROW || e.keyCode === KEYCODE_RIGHT_ARROW) {
  27. // increment number of example
  28. example = parseInt(example) + 1
  29. console.log("I'm here")
  30. // construct url with params for experiments
  31. const params = `?scene=${scene}&expe=${expe}&example=${example}`
  32. window.location = indicationsUrl + params
  33. }
  34. }
  35. // implement `key` events
  36. document.addEventListener('keydown', checkKey)