Commit 1278bf51 authored by Zhai Zirun's avatar Zhai Zirun

got connecting to the database client to compile

parent 554cf336
web: node index.js
\ No newline at end of file
......@@ -3,19 +3,26 @@ var MOUSE_VISITED_CLASSNAME = 'crx_mouse_visited';
var srcName;
var dietNum = 0;
// var currName;
var currName;
//Querying database on heroku
// import { Client } from 'pg';
// const client = new Client({
// connectionString: process.env.DATABASE_URL, //default name for main database is DATABASE_URL
// ssl: {
// rejectUnauthorized: false
// }
// });
//https://www.w3schools.com/nodejs/nodejs_mysql_select.asp
// 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;
// });
// }
// Previous dom, that we want to track, so we can remove the previous styling.
......@@ -39,9 +46,12 @@ document.addEventListener('mousemove', function (e) {
// if (srcName == "Waitrose coffee & walnut cake") {
// srcElement.classList.add(MOUSE_VISITED_CLASSNAME);
// }
// currName = srcElement.srcName;
srcElement.classList.add(MOUSE_VISITED_CLASSNAME); //changes outline of pic
currName = srcElement.srcName;
if (true) {
srcElement.classList.add(MOUSE_VISITED_CLASSNAME); //changes outline of pic
//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;
......@@ -65,21 +75,5 @@ function myFunction() {
dietNum = a + (b << 1) + (c << 2) + (d << 3);
}
// 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;
// });
// }
import { Client } from 'pg';
const client = new Client({
connectionString: process.env.DATABASE_URL, //default name for main database is DATABASE_URL
ssl: {
rejectUnauthorized: false
}
});
//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
// problem: connecting to the client within content.js?
// --> figure out how to call function from diff javascript file? and put the function here in index.js
// problem: cost of calling database that many times?
// --> probably not a big deal, can ignore (?)
// 2. store the entire database in the cache or something and load it once at startup
// problem: slows down the browser probably lmao
// --> cant really fix this? unless its negligible but i dont think so (?)
\ No newline at end of file
......@@ -9,11 +9,6 @@
"declarativeContent"
],
"permissions": [
"activeTab",
"declarativeContent"
],
"browser_action": {
"default_icon": "images/example-icon.png",
"default_title": "Clickerance",
......
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