Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Zhai, Zirun
Clickerance
Commits
bbd62e12
Commit
bbd62e12
authored
Sep 05, 2020
by
Zhai Zirun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
query function returns presence of specific ingredient in product
parent
645df31b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
10 deletions
+64
-10
content.js
content.js
+28
-6
test.js
test.js
+36
-4
No files found.
content.js
View file @
bbd62e12
...
...
@@ -2,13 +2,20 @@
var
MOUSE_VISITED_CLASSNAME
=
'
crx_mouse_visited_true
'
;
var
MOUSE_VISITED_CLASSNAME_FALSE
=
'
crx_mouse_visited_false
'
;
const
Ingredient
=
{
GLUTEN
:
1
,
DAIRY
:
2
,
CORN
:
3
,
MEAT
:
4
};
function
query
(
product
)
{
function
query
(
product
,
ingredient
)
{
const
sqlite3
=
require
(
'
sqlite3
'
).
verbose
();
let
db
=
new
sqlite3
.
Database
(
'
./public.db
'
,
sqlite3
.
OPEN_READONLY
,
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
err
.
message
);
console
.
error
(
'
Error connecting to database
'
);
}
console
.
log
(
'
Connected to the in-memory SQlite database.
'
);
});
...
...
@@ -22,13 +29,28 @@ function query(product) {
db
.
get
(
sql
,
product
,
(
err
,
row
)
=>
{
if
(
err
)
{
return
console
.
error
(
err
.
message
);
return
console
.
error
(
'
Error querying database
'
);
}
if
(
!
row
)
{
return
console
.
error
(
`No product found with the name
${
product
}
`
);
}
switch
(
ingredient
)
{
case
Ingredient
.
GLUTEN
:
return
row
.
cg
;
case
Ingredient
.
DAIRY
:
return
row
.
cd
;
case
Ingredient
.
CORN
:
return
row
.
cc
;
case
Ingredient
.
MEAT
:
return
row
.
cm
;
default
:
break
;
}
return
row
?
console
.
log
(
row
.
cg
)
:
console
.
log
(
`No product found with the name
${
product
}
`
);
});
db
.
close
();
}
...
...
test.js
View file @
bbd62e12
const
Ingredient
=
{
GLUTEN
:
1
,
DAIRY
:
2
,
CORN
:
3
,
MEAT
:
4
};
const
sqlite3
=
require
(
'
sqlite3
'
).
verbose
();
let
db
=
new
sqlite3
.
Database
(
'
./public.db
'
,
sqlite3
.
OPEN_READONLY
,
(
err
)
=>
{
...
...
@@ -7,6 +15,8 @@ const sqlite3 = require('sqlite3').verbose();
console
.
log
(
'
Connected to the in-memory SQlite database.
'
);
});
let
ingredient
=
Ingredient
.
GLUTEN
;
let
product
=
'
Waitrose Millionaire Bites
'
let
sql
=
`SELECT Containsgluten cg,
Containsdairy cd,
...
...
@@ -20,8 +30,30 @@ const sqlite3 = require('sqlite3').verbose();
if
(
err
)
{
return
console
.
error
(
err
.
message
);
}
return
row
?
console
.
log
(
row
.
cg
)
:
console
.
log
(
`No product found with the name
${
product
}
`
);
switch
(
ingredient
)
{
case
Ingredient
.
GLUTEN
:
return
row
?
console
.
log
(
row
.
cg
)
:
console
.
log
(
`No product found with the name
${
product
}
`
);
case
Ingredient
.
DAIRY
:
return
row
?
console
.
log
(
row
.
cd
)
:
console
.
log
(
`No product found with the name
${
product
}
`
);
case
Ingredient
.
CORN
:
return
row
?
console
.
log
(
row
.
cc
)
:
console
.
log
(
`No product found with the name
${
product
}
`
);
case
Ingredient
.
MEAT
:
return
row
?
console
.
log
(
row
.
cm
)
:
console
.
log
(
`No product found with the name
${
product
}
`
);
default
:
break
;
}
});
db
.
close
();
\ No newline at end of file
db
.
close
((
err
)
=>
{
if
(
err
)
{
console
.
error
(
err
.
message
);
}
console
.
log
(
'
Database connection closed.
'
);
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment