Commit f998704b authored by Zhai Zirun's avatar Zhai Zirun

main problem now is that require is not defined

parent a0b79530
// Unique ID for the className.
var MOUSE_VISITED_CLASSNAME = 'crx_mouse_visited';
var srcName;
var dietNum = 0;
var currName;
//Querying database on heroku
// function checkAllergens() {
// client.connect();
// //TODO: find a way to connect to client at startup (le??) to remove the need to connect and disconnect repeatedly
// //TODO: fill in names of columns of db
// client.query('SELECT Containsgluten, Containsdairy, Containscorn, Containsmeat FROM productsIngredients WHERE Product = currName;', (err, res) => {
// if (err) throw err;
// for (let col of res.cols) {
// if (col) {
// return col;
// }
// //returns true if any allergen is present.
// //TODO: modify behaviour according to different allergens
// }
// client.end();
// return false;
// });
// }
const { Client } = require('pg');
const client = new Client({
connectionString: process.env.DATABASE_URL, //default name for main database is DATABASE_URL
ssl: {
rejectUnauthorized: false
}
});
// Previous dom, that we want to track, so we can remove the previous styling.
//var prevDOM = null;
function checkAllergens(name) {
client.connect();
client.query('SELECT Containsgluten, Containsdairy, Containscorn, Containsmeat FROM productsIngredients WHERE Product = ' + name + ';', (err, res) => {
if (err) throw err;
for (let col of res.cols) {
if (col) {
return col;
}
//returns true if any allergen is present.
}
return false;
});
client.end();
// return true;
}
// Mouse listener for any move event on the current document.
document.addEventListener('mousemove', function (e) {
let srcElement = e.srcElement;
......@@ -35,7 +36,6 @@ document.addEventListener('mousemove', function (e) {
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) {
......@@ -46,9 +46,8 @@ document.addEventListener('mousemove', function (e) {
// if (srcName == "Waitrose coffee & walnut cake") {
// srcElement.classList.add(MOUSE_VISITED_CLASSNAME);
// }
currName = srcElement.srcName;
if (true) {
if (checkAllergens(srcElement.alt)) {
srcElement.classList.add(MOUSE_VISITED_CLASSNAME); //changes outline of pic
//TODO: modify behaviour according to different allergens
}
......
import { Client } from 'pg';
const { Client } = require('pg');
const client = new Client({
connectionString: process.env.DATABASE_URL, //default name for main database is DATABASE_URL
......@@ -9,21 +8,6 @@ const client = new Client({
});
//https://www.w3schools.com/nodejs/nodejs_mysql_select.asp
client.connect();
//TODO: find a way to connect to client at startup (le??) to remove the need to connect and disconnect repeatedly
//TODO: fill in names of columns of db
client.query('SELECT Containsgluten, Containsdairy, Containscorn, Containsmeat FROM productsIngredients WHERE Product = currName;', (err, res) => {
if (err) throw err;
// for (let col of res.cols) {
// if (col) {
// return col;
// }
// //returns true if any allergen is present.
// //TODO: modify behaviour according to different allergens
// }
client.end();
});
// two options for accessing database:
// 1. make it a function and connect and reconnect to the client each time we hover over an icon
......
......@@ -4,7 +4,9 @@
<meta charset = "utf-8"/>
<title> clickerance </title>
<link type="text/css" rel="stylesheet" href="style.css"/>
<script src="content.js"></script>
<script src="require.js" type="text/javascript"></script>
<script src="index.js" type="text/javascript"></script>
<script src="content.js" type="text/javascript"></script>
</head>
<body>
<div class="Title">
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment