Commit 37672aad authored by Zhai Zirun's avatar Zhai Zirun

added sql.js submodule

parent b74dd250
[submodule "sql.js"]
path = sql.js
url = https://github.com/sql-js/sql.js
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Bundle = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
// 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 requestResult;
var dietNum = 0;
......@@ -43,57 +43,55 @@ function query(product) {
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)))
return !((cd && (1 && dietNum)) || (cm && (2 && dietNum)) || (cc && (4 && dietNum)) || (cg && (8 && dietNum)))
});
db.close();
}
function callBack(canEat) {
if (canEat == undefined) {
requestResult = true;
} else if (canEat == "0") {
requestResult = true;
} else if (canEat == "1") {
requestResult = true;
} else if (canEat == "Could not connect") {
result = true;
} else if (canEat == 1) {
requestResult = true;
} else if (canEat == '1') {
requestResult = true;
}
}
function checkAllergen(product) {
request(product);
return requestResult;
}
function checkAllergen(product) {
var xhr = new XMLHttpRequest();
var result;
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var canEat = this.responseText;
if (canEat == undefined) {
result = false;
} else if (canEat == "0") {
result = false;
} else if (canEat == "1") {
result = true;
} else if (canEat == "Could not connect") {
result = false;
}
}
};
xhr.open("GET", "script.php?q="+product, true);
xhr.send();
return result;
}
// function callBack(canEat) {
// if (canEat == undefined) {
// requestResult = true;
// } else if (canEat == "0") {
// requestResult = true;
// } else if (canEat == "1") {
// requestResult = true;
// } else if (canEat == "Could not connect") {
// result = true;
// } else if (canEat == 1) {
// requestResult = true;
// } else if (canEat == '1') {
// requestResult = true;
// }
// }
// function checkAllergen(product) {
// request(product);
// return requestResult;
// }
// function checkAllergen(product) {
// var xhr = new XMLHttpRequest();
// var result;
// xhr.onreadystatechange = function() {
// if (this.readyState == 4 && this.status == 200) {
// var canEat = this.responseText;
// if (canEat == undefined) {
// result = false;
// } else if (canEat == "0") {
// result = false;
// } else if (canEat == "1") {
// result = true;
// } else if (canEat == "Could not connect") {
// result = false;
// }
// }
// };
// xhr.open("GET", "script.php?q="+product, true);
// xhr.send();
// return result;
// }
// Previous dom, that we want to track, so we can remove the previous styling.
......@@ -20219,5 +20217,4 @@ arguments[4][86][0].apply(exports,arguments)
arguments[4][87][0].apply(exports,arguments)
},{"dup":87}],129:[function(require,module,exports){
arguments[4][88][0].apply(exports,arguments)
},{"./support/isBuffer":128,"_process":102,"dup":88,"inherits":127}]},{},[1])(1)
});
},{"./support/isBuffer":128,"_process":102,"dup":88,"inherits":127}]},{},[1]);
......@@ -4,7 +4,7 @@ var MOUSE_VISITED_CLASSNAME_FALSE = 'crx_mouse_visited_false';
var srcName;
var requestResult;
// var requestResult;
var dietNum = 0;
......@@ -16,83 +16,81 @@ function dietNumInit() {
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 = ?`;
// 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();
}
function callBack(canEat) {
if (canEat == undefined) {
requestResult = true;
} else if (canEat == "0") {
requestResult = true;
} else if (canEat == "1") {
requestResult = true;
} else if (canEat == "Could not connect") {
result = true;
} else if (canEat == 1) {
requestResult = true;
} else if (canEat == '1') {
requestResult = true;
}
}
function checkAllergen(product) {
request(product);
return requestResult;
}
function checkAllergen(product) {
var xhr = new XMLHttpRequest();
var result;
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var canEat = this.responseText;
if (canEat == undefined) {
result = false;
} else if (canEat == "0") {
result = false;
} else if (canEat == "1") {
result = true;
} else if (canEat == "Could not connect") {
result = false;
}
}
};
xhr.open("GET", "script.php?q="+product, true);
xhr.send();
return result;
}
// 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 !((cd && (1 && dietNum)) || (cm && (2 && dietNum)) || (cc && (4 && dietNum)) || (cg && (8 && dietNum)))
// });
// db.close();
// }
// function callBack(canEat) {
// if (canEat == undefined) {
// requestResult = true;
// } else if (canEat == "0") {
// requestResult = true;
// } else if (canEat == "1") {
// requestResult = true;
// } else if (canEat == "Could not connect") {
// result = true;
// } else if (canEat == 1) {
// requestResult = true;
// } else if (canEat == '1') {
// requestResult = true;
// }
// }
// function checkAllergen(product) {
// request(product);
// return requestResult;
// }
// function checkAllergen(product) {
// var xhr = new XMLHttpRequest();
// var result;
// xhr.onreadystatechange = function() {
// if (this.readyState == 4 && this.status == 200) {
// var canEat = this.responseText;
// if (canEat == undefined) {
// result = false;
// } else if (canEat == "0") {
// result = false;
// } else if (canEat == "1") {
// result = true;
// } else if (canEat == "Could not connect") {
// result = false;
// }
// }
// };
// xhr.open("GET", "script.php?q="+product, true);
// xhr.send();
// return result;
// }
// Previous dom, that we want to track, so we can remove the previous styling.
......@@ -117,10 +115,10 @@ document.addEventListener('mousemove', function (e) {
// srcElement.classList.add(MOUSE_VISITED_CLASSNAME);
// }
// currName = srcElement.srcName;
if (query(srcName)) {
if (true) {
srcElement.classList.add(MOUSE_VISITED_CLASSNAME); //changes outline of pic
}
if (!query(srcName)) {
if (!true) {
srcElement.classList.add(MOUSE_VISITED_CLASSNAME_FALSE);
}
//TODO: modify behaviour according to different allergens
......
{
"node": true,
"browser": false,
"esnext": true,
"bitwise": false,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"immed": true,
"indent": 2,
"latedef": true,
"laxbreak": true,
"newcap": true,
"noarg": true,
"quotmark": "double",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"globals": {
"define": false
}
}
example
tests
autotest.watchr
Copyright (c) 2010 passive.ly LLC
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
# node-XMLHttpRequest #
node-XMLHttpRequest is a wrapper for the built-in http client to emulate the
browser XMLHttpRequest object.
This can be used with JS designed for browsers to improve reuse of code and
allow the use of existing libraries.
Note: This library currently conforms to [XMLHttpRequest 1](http://www.w3.org/TR/XMLHttpRequest/). Version 2.0 will target [XMLHttpRequest Level 2](http://www.w3.org/TR/XMLHttpRequest2/).
## Usage ##
Here's how to include the module in your project and use as the browser-based
XHR object.
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
Note: use the lowercase string "xmlhttprequest" in your require(). On
case-sensitive systems (eg Linux) using uppercase letters won't work.
## Versions ##
Prior to 1.4.0 version numbers were arbitrary. From 1.4.0 on they conform to
the standard major.minor.bugfix. 1.x shouldn't necessarily be considered
stable just because it's above 0.x.
Since the XMLHttpRequest API is stable this library's API is stable as
well. Major version numbers indicate significant core code changes.
Minor versions indicate minor core code changes or better conformity to
the W3C spec.
## License ##
MIT license. See LICENSE for full details.
## Supports ##
* Async and synchronous requests
* GET, POST, PUT, and DELETE requests
* All spec methods (open, send, abort, getRequestHeader,
getAllRequestHeaders, event methods)
* Requests to all domains
## Known Issues / Missing Features ##
For a list of open issues or to report your own visit the [github issues
page](https://github.com/driverdan/node-XMLHttpRequest/issues).
* Local file access may have unexpected results for non-UTF8 files
* Synchronous requests don't set headers properly
* Synchronous requests freeze node while waiting for response (But that's what you want, right? Stick with async!).
* Some events are missing, such as abort
* Cookies aren't persisted between requests
* Missing XML support
/**
* Wrapper for built-in http.js to emulate the browser XMLHttpRequest object.
*
* This can be used with JS designed for browsers to improve reuse of code and
* allow the use of existing libraries.
*
* Usage: include("XMLHttpRequest.js") and use XMLHttpRequest per W3C specs.
*
* @author Dan DeFelippi <dan@driverdan.com>
* @contributor David Ellis <d.f.ellis@ieee.org>
* @license MIT
*/
var Url = require("url");
var spawn = require("child_process").spawn;
var fs = require("fs");
exports.XMLHttpRequest = function() {
"use strict";
/**
* Private variables
*/
var self = this;
var http = require("http");
var https = require("https");
// Holds http.js objects
var request;
var response;
// Request settings
var settings = {};
// Disable header blacklist.
// Not part of XHR specs.
var disableHeaderCheck = false;
// Set some default headers
var defaultHeaders = {
"User-Agent": "node-XMLHttpRequest",
"Accept": "*/*",
};
var headers = {};
var headersCase = {};
// These headers are not user setable.
// The following are allowed but banned in the spec:
// * user-agent
var forbiddenRequestHeaders = [
"accept-charset",
"accept-encoding",
"access-control-request-headers",
"access-control-request-method",
"connection",
"content-length",
"content-transfer-encoding",
"cookie",
"cookie2",
"date",
"expect",
"host",
"keep-alive",
"origin",
"referer",
"te",
"trailer",
"transfer-encoding",
"upgrade",
"via"
];
// These request methods are not allowed
var forbiddenRequestMethods = [
"TRACE",
"TRACK",
"CONNECT"
];
// Send flag
var sendFlag = false;
// Error flag, used when errors occur or abort is called
var errorFlag = false;
// Event listeners
var listeners = {};
/**
* Constants
*/
this.UNSENT = 0;
this.OPENED = 1;
this.HEADERS_RECEIVED = 2;
this.LOADING = 3;
this.DONE = 4;
/**
* Public vars
*/
// Current state
this.readyState = this.UNSENT;
// default ready state change handler in case one is not set or is set late
this.onreadystatechange = null;
// Result & response
this.responseText = "";
this.responseXML = "";
this.status = null;
this.statusText = null;
// Whether cross-site Access-Control requests should be made using
// credentials such as cookies or authorization headers
this.withCredentials = false;
/**
* Private methods
*/
/**
* Check if the specified header is allowed.
*
* @param string header Header to validate
* @return boolean False if not allowed, otherwise true
*/
var isAllowedHttpHeader = function(header) {
return disableHeaderCheck || (header && forbiddenRequestHeaders.indexOf(header.toLowerCase()) === -1);
};
/**
* Check if the specified method is allowed.
*
* @param string method Request method to validate
* @return boolean False if not allowed, otherwise true
*/
var isAllowedHttpMethod = function(method) {
return (method && forbiddenRequestMethods.indexOf(method) === -1);
};
/**
* Public methods
*/
/**
* Open the connection. Currently supports local server requests.
*
* @param string method Connection method (eg GET, POST)
* @param string url URL for the connection.
* @param boolean async Asynchronous connection. Default is true.
* @param string user Username for basic authentication (optional)
* @param string password Password for basic authentication (optional)
*/
this.open = function(method, url, async, user, password) {
this.abort();
errorFlag = false;
// Check for valid request method
if (!isAllowedHttpMethod(method)) {
throw new Error("SecurityError: Request method not allowed");
}
settings = {
"method": method,
"url": url.toString(),
"async": (typeof async !== "boolean" ? true : async),
"user": user || null,
"password": password || null
};
setState(this.OPENED);
};
/**
* Disables or enables isAllowedHttpHeader() check the request. Enabled by default.
* This does not conform to the W3C spec.
*
* @param boolean state Enable or disable header checking.
*/
this.setDisableHeaderCheck = function(state) {
disableHeaderCheck = state;
};
/**
* Sets a header for the request or appends the value if one is already set.
*
* @param string header Header name
* @param string value Header value
*/
this.setRequestHeader = function(header, value) {
if (this.readyState !== this.OPENED) {
throw new Error("INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN");
}
if (!isAllowedHttpHeader(header)) {
console.warn("Refused to set unsafe header \"" + header + "\"");
return;
}
if (sendFlag) {
throw new Error("INVALID_STATE_ERR: send flag is true");
}
header = headersCase[header.toLowerCase()] || header;
headersCase[header.toLowerCase()] = header;
headers[header] = headers[header] ? headers[header] + ', ' + value : value;
};
/**
* Gets a header from the server response.
*
* @param string header Name of header to get.
* @return string Text of the header or null if it doesn't exist.