Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Unique ID for the className.
- var MOUSE_VISITED_CLASSNAME = 'crx_mouse_visited_true';
- var MOUSE_VISITED_CLASSNAME_FALSE = 'crx_mouse_visited_false';
- var srcName;
- var requestResult;
- var dietNum = 0;
- function dietNumInit() {
- var a = document.getElementById("Dairy").checked;
- var b = document.getElementById("Meat").checked;
- var c = document.getElementById("Corn").checked;
- var d = document.getElementById("Gluten").checked;
- dietNum = a + (b << 1) + (c << 2) + (d << 3);
- }
- function query(product) {
- const sqlite3 = require('sqlite3').verbose();
- let db = new sqlite3.Database('./public.db', sqlite3.OPEN_READONLY, (err) => {
- if (err) {
- console.error('Error connecting to database');
- }
- console.log('Connected to the in-memory SQlite database.');
- });
- let sql = `SELECT Containsdairy cd,
- Containsmeat cm,
- Containscorn cc,
- Containsgluten cg
- FROM productsIngredients
- WHERE Product = ?`;
- db.get(sql, product, (err, row) => {
- if (err) {
- return console.error('Error querying database');
- }
- if (!row) {
- return console.error(`No product found with the name ${product}`);
- }
- return row.cg
- //return !((cd && (1 && dietNum)) || (cm && (2 && dietNum)) || (cc && (4 && dietNum)) || (cg && (8 && dietNum)))
- });
- db.close();
- }
- // Previous dom, that we want to track, so we can remove the previous styling.
- //var prevDOM = null;
- // Mouse listener for any move event on the current document.
- document.addEventListener('mousemove', function (e) {
- let srcElement = e.srcElement;
- // Lets check if our underlying element contains any allergens.
- if (srcElement.nodeName == 'IMG') {
- //if (srcElement.nodeName == 'DIV' && srcElement.className == "content___1O9rr") {
- //prevDOM != srcElement &&
- srcName = srcElement.alt;
- // For NPE checking, we check safely. We need to remove the class name
- // Since we will be styling the new one after.
- // if (prevDOM != null) {
- // prevDOM.classList.remove(MOUSE_VISITED_CLASSNAME);
- // }
- // Add a visited class name to the element. So we can style it.
- // if (srcName == "Waitrose coffee & walnut cake") {
- // srcElement.classList.add(MOUSE_VISITED_CLASSNAME);
- // }
- // currName = srcElement.srcName;
- if (query(srcName)) {
- srcElement.classList.add(MOUSE_VISITED_CLASSNAME); //changes outline of pic
- }
- if (!query(srcName)) {
- srcElement.classList.add(MOUSE_VISITED_CLASSNAME_FALSE);
- }
- //TODO: modify behaviour according to different allergens
- // The current element is now the previous. So we can remove the class
- // during the next ieration.
- //prevDOM = srcElement;
- console.info(srcElement.currentSrc);
- console.dir(srcElement);
- }
- }, false);
- if(document){
- document.addEventListener("DOMContentLoaded", function() {
- document.getElementById("Submit").addEventListener("click", dietNumInit);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment