Guest User

Untitled

a guest
Sep 7th, 2020
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. // Unique ID for the className.
  2. var MOUSE_VISITED_CLASSNAME = 'crx_mouse_visited_true';
  3. var MOUSE_VISITED_CLASSNAME_FALSE = 'crx_mouse_visited_false';
  4.  
  5.  
  6. var srcName;
  7. var requestResult;
  8.  
  9. var dietNum = 0;
  10.  
  11. function dietNumInit() {
  12. var a = document.getElementById("Dairy").checked;
  13. var b = document.getElementById("Meat").checked;
  14. var c = document.getElementById("Corn").checked;
  15. var d = document.getElementById("Gluten").checked;
  16. dietNum = a + (b << 1) + (c << 2) + (d << 3);
  17. }
  18.  
  19. function query(product) {
  20. const sqlite3 = require('sqlite3').verbose();
  21.  
  22. let db = new sqlite3.Database('./public.db', sqlite3.OPEN_READONLY, (err) => {
  23. if (err) {
  24. console.error('Error connecting to database');
  25. }
  26. console.log('Connected to the in-memory SQlite database.');
  27. });
  28.  
  29. let sql = `SELECT Containsdairy cd,
  30. Containsmeat cm,
  31. Containscorn cc,
  32. Containsgluten cg
  33. FROM productsIngredients
  34. WHERE Product = ?`;
  35.  
  36.  
  37. db.get(sql, product, (err, row) => {
  38.  
  39. if (err) {
  40. return console.error('Error querying database');
  41. }
  42. if (!row) {
  43. return console.error(`No product found with the name ${product}`);
  44. }
  45.  
  46. return row.cg
  47. //return !((cd && (1 && dietNum)) || (cm && (2 && dietNum)) || (cc && (4 && dietNum)) || (cg && (8 && dietNum)))
  48. });
  49.  
  50. db.close();
  51. }
  52.  
  53.  
  54.  
  55. // Previous dom, that we want to track, so we can remove the previous styling.
  56. //var prevDOM = null;
  57.  
  58. // Mouse listener for any move event on the current document.
  59. document.addEventListener('mousemove', function (e) {
  60. let srcElement = e.srcElement;
  61. // Lets check if our underlying element contains any allergens.
  62. if (srcElement.nodeName == 'IMG') {
  63. //if (srcElement.nodeName == 'DIV' && srcElement.className == "content___1O9rr") {
  64. //prevDOM != srcElement &&
  65. srcName = srcElement.alt;
  66. // For NPE checking, we check safely. We need to remove the class name
  67. // Since we will be styling the new one after.
  68. // if (prevDOM != null) {
  69. // prevDOM.classList.remove(MOUSE_VISITED_CLASSNAME);
  70. // }
  71.  
  72. // Add a visited class name to the element. So we can style it.
  73. // if (srcName == "Waitrose coffee & walnut cake") {
  74. // srcElement.classList.add(MOUSE_VISITED_CLASSNAME);
  75. // }
  76. // currName = srcElement.srcName;
  77. if (query(srcName)) {
  78. srcElement.classList.add(MOUSE_VISITED_CLASSNAME); //changes outline of pic
  79. }
  80. if (!query(srcName)) {
  81. srcElement.classList.add(MOUSE_VISITED_CLASSNAME_FALSE);
  82. }
  83. //TODO: modify behaviour according to different allergens
  84. // The current element is now the previous. So we can remove the class
  85. // during the next ieration.
  86. //prevDOM = srcElement;
  87. console.info(srcElement.currentSrc);
  88. console.dir(srcElement);
  89. }
  90. }, false);
  91.  
  92. if(document){
  93. document.addEventListener("DOMContentLoaded", function() {
  94. document.getElementById("Submit").addEventListener("click", dietNumInit);
  95. });
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment