index.html 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Instascan</title>
  5. <script type="text/javascript" src="https://rawgit.com/schmich/instascan-builds/master/instascan.min.js"></script>
  6. </head>
  7. <body>
  8. <h1>Scanner QrCODE</h1>
  9. <video id="preview"></video>
  10. <script type="text/javascript">
  11. //Recupération du cookie espace
  12. function getCookieVal(offset) {
  13. let endstr = document.cookie.indexOf (";", offset);
  14. if (endstr==-1)
  15. endstr = document.cookie.length;
  16. return unescape(document.cookie.substring(offset, endstr));
  17. }
  18. function getCookie (name) {
  19. let arg = name + "=";
  20. let alen = arg.length;
  21. let clen = document.cookie.length;
  22. let i = 0;
  23. while (i < clen) {
  24. let j = i+alen;
  25. if (document.cookie.substring(i, j) == arg)
  26. return getCookieVal(j);
  27. i = document.cookie.indexOf(" ",i)+1;
  28. if (i == 0)
  29. break;
  30. }
  31. return null;
  32. }
  33. let espace = getCookie("microfolies.lens.espace");
  34. console.log(espace);
  35. //Scanner QRcode
  36. let scanner = new Instascan.Scanner({ video: document.getElementById('preview') });
  37. scanner.addListener('scan', function (content) {
  38. espace ? console.log(content + "/" + espace) : console.log(content);
  39. });
  40. Instascan.Camera.getCameras().then(function (cameras) {
  41. if (cameras.length > 0) {
  42. scanner.start(cameras[0]);
  43. }
  44. else {
  45. console.error('No cameras found.');
  46. }
  47. }).catch(function (e) {
  48. console.error(e);
  49. });
  50. </script>
  51. </body>
  52. </html>