Commit 3df020f4 authored by ianzren's avatar ianzren

Fixed messaging between popup and content.js

added popup.js
parent e547647c
var MOUSE_VISITED_CLASSNAME = 'crx_mouse_visited_true';
var MOUSE_VISITED_CLASSNAME_FALSE = 'crx_mouse_visited_false';
var srcName;
var dietNum = 0;
var dietNum = 999;
function dietNumInit() {
dietNum = a + (b << 1) + (c << 2) + (d << 3);
}
// 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);
// document.getElementById('demo').textContent = dietNum;
// }
function checkAllergen(product) {
var promise = new Promise(function(resolve, reject) {
......@@ -18,7 +23,7 @@ function checkAllergen(product) {
}
};
xhr.onerror = () => reject(xhr.status);
xhr.open("GET", "http://localhost/script.php?product="+product+"&dietNum="+2, true);
xhr.open("GET", "http://localhost/script.php?product="+product+"&dietNum="+dietNum, true);
xhr.send();
});
return promise;
......@@ -27,11 +32,12 @@ function checkAllergen(product) {
document.addEventListener('mousemove', function (e) {
let srcElement = e.srcElement;
if (srcElement.nodeName == 'IMG') {
if (srcElement.nodeName == 'IMG' && dietNum != 999) {
srcName = srcElement.alt;
promise = checkAllergen(srcName).then(
function(responseText) {
console.log("Success");
console.log(dietNum);
if (responseText == "1" || responseText == undefined) {
srcElement.classList.add(MOUSE_VISITED_CLASSNAME);
} else if (responseText == "0") {
......@@ -48,9 +54,11 @@ document.addEventListener('mousemove', function (e) {
console.dir(srcElement);
}
}, false);
if(document){
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("Submit").addEventListener("click", dietNumInit);
});
}
\ No newline at end of file
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
dietNum = request.dietNum;
});
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p id="demo">=a</p>
<button type="button" id="do-count">Count</button>
<script src="popup.js"></script>
</body>
</html>
\ No newline at end of file
......@@ -5,6 +5,7 @@
"manifest_version" : 2,
"permissions": [
"tabs",
"activeTab",
"declarativeContent",
"https://www.waitrose.com/",
......@@ -17,10 +18,6 @@
"default_popup": "popup.html"
},
"background": {
"scripts": ["background.js"],
"persistent": false
},
"content_scripts": [{
"css": ["style.css"],
......
{
"_from": "sql-js",
"_from": "sql-js@^0.1.0",
"_id": "sql-js@0.1.0",
"_inBundle": false,
"_integrity": "sha1-OSkM2Rv7yd/8G+Gy+g6WGF7ZQGc=",
"_location": "/sql-js",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"type": "range",
"registry": true,
"raw": "sql-js",
"raw": "sql-js@^0.1.0",
"name": "sql-js",
"escapedName": "sql-js",
"rawSpec": "",
"rawSpec": "^0.1.0",
"saveSpec": null,
"fetchSpec": "latest"
"fetchSpec": "^0.1.0"
},
"_requiredBy": [
"#USER",
......@@ -21,8 +21,8 @@
],
"_resolved": "https://registry.npmjs.org/sql-js/-/sql-js-0.1.0.tgz",
"_shasum": "39290cd91bfbc9dffc1be1b2fa0e96185ed94067",
"_spec": "sql-js",
"_where": "C:\\Clickerance\\chrome-groceries-extension",
"_spec": "sql-js@^0.1.0",
"_where": "C:\\Users\\IanZr\\OneDrive\\Desktop\\git clone\\chrome-groceries-extension",
"author": {
"name": "alex030293"
},
......
../sql.js
\ No newline at end of file
"use strict";
module.exports = {
env: {
browser: true,
es6: true,
node: true
},
extends: [
"airbnb-base"
],
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly"
},
ignorePatterns: [
"/dist/",
"/examples/",
"/node_modules/",
"/out/",
"/src/shell-post.js",
"/src/shell-pre.js",
"/test/",
"!/.eslintrc.js"
],
parserOptions: {
ecmaVersion: 5,
sourceType: "script"
},
rules: {
// reason - sqlite exposes functions with underscore-naming-convention
camelcase: "off",
// reason - They make it easier to add new elements to arrays
// and parameters to functions, and make commit diffs clearer
"comma-dangle": "off",
// reason - string-notation needed to prevent closure-minifier
// from mangling property-name
"dot-notation": "off",
// reason - enforce 4-space indent
indent: ["error", 4, { SwitchCase: 1 }],
// reason - enforce 80-column-width limit
"max-len": ["error", { code: 80 }],
// reason - src/api.js uses bitwise-operators
"no-bitwise": "off",
"no-cond-assign": ["error", "except-parens"],
"no-param-reassign": "off",
"no-throw-literal": "off",
// reason - parserOptions is set to es5 language-syntax
"no-var": "off",
// reason - parserOptions is set to es5 language-syntax
"object-shorthand": "off",
// reason - parserOptions is set to es5 language-syntax
"prefer-arrow-callback": "off",
// reason - parserOptions is set to es5 language-syntax
"prefer-destructuring": "off",
// reason - parserOptions is set to es5 language-syntax
"prefer-spread": "off",
// reason - parserOptions is set to es5 language-syntax
"prefer-template": "off",
// reason - sql.js frequently use sql-query-strings containing
// single-quotes
quotes: ["error", "double"],
// reason - allow top-level "use-strict" in commonjs-modules
strict: ["error", "safe"],
"vars-on-top": "off"
}
};
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
id: cache
with:
path: '.emsdk-cache'
key: emscripten-1.39.20
- uses: mymindstorm/setup-emsdk@2a4a91b
with:
version: '1.39.20'
actions-cache-folder: '.emsdk-cache'
- name: make
run: make
- uses: actions/upload-artifact@v2
with: {name: dist, path: dist}
- name: test
run: npm ci && npm test
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
name: Create a release
jobs:
build:
name: Create a release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: mymindstorm/setup-emsdk@2a4a91b
with: {version: '1.39.20'}
- name: make
run: make
- name: Create Release
id: create_release
uses: actions/create-release@v1.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- run: cd dist && zip sqljs-wasm.zip sql-wasm.{js,wasm}
- name: Upload Release Asset (wasm)
uses: lovasoa/upload-release-asset@851d9cc
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/sqljs-wasm.zip
asset_name: sqljs-wasm.zip
asset_label: wasm version, best runtime performance, smaller assets, requires configuration
asset_content_type: application/zip
- name: Upload Release Asset (asm)
uses: lovasoa/upload-release-asset@851d9cc
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/sql-asm.js
asset_name: sql.js
asset_label: asm.js version, slower, easy to integrate and compatible with old browsers
asset_content_type: text/javascript
- run: cd dist && zip sqljs-worker-wasm.zip worker.sql-wasm.js sql-wasm.wasm
- name: Upload Release Asset (worker wasm)
uses: lovasoa/upload-release-asset@851d9cc
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/sqljs-worker-wasm.zip
asset_name: sqljs-worker-wasm.zip
asset_label: webworker wasm version, to be loaded as a web worker
asset_content_type: application/zip
- name: Upload Release Asset (worker asm)
uses: lovasoa/upload-release-asset@851d9cc
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/worker.sql-asm.js
asset_name: worker.sql-asm.js
asset_label: webworker asm version, to be loaded as a web worker
asset_content_type: text/javascript
- run: cd dist && zip sqljs-all.zip *.{js,wasm}
- name: Upload Release Asset (all)
uses: lovasoa/upload-release-asset@851d9cc
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/sqljs-all.zip
asset_name: sqljs-all.zip
asset_label: all versions, including non-minified javascript
asset_content_type: application/zip
- name: publish the package to NPM
run: |
npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
npm publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
node_modules/
*~
# Intermediary files:
cache/
out/
sqlite-src/
tmp/
c/
emsdk/
sqljs.zip
{
"plugins": [
"plugins/markdown"
],
"source": {
"include": [
"src/api.js"
]
}
}
\ No newline at end of file
test/
c/
gh-pages/
node_modules/
node-debug.log
src/
cache/
out/
examples/
sqlite-src/
.git/
index.html
.github
Makefile
emsdk_set_env.sh
sqljs.zip
Ophir LOJKINE <pere.jobs@gmail.com> (https://github.com/lovasoa)
@kripken
@hankinsoft
@firien
@dinedal
@taytay
@kaizhu256
@brodybits
<html>
<body>
<!-- Add a link to the new page because there are likely links pointing here from elsewhere -->
This page has moved to: <a href="../examples/GUI/index.html">../examples/GUI/index.html</a>
</body>
</html>
\ No newline at end of file
MIT license
===========
Copyright (c) 2017 sql.js authors (see AUTHORS)
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.
# Some portions of the Makefile taken from:
Copyright 2017 Ryusei Yamaguchi
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.
\ No newline at end of file
# Note: Last built with version 1.38.30 of Emscripten
# TODO: Emit a file showing which version of emcc and SQLite was used to compile the emitted output.
# TODO: Create a release on Github with these compiled assets rather than checking them in
# TODO: Consider creating different files based on browser vs module usage: https://github.com/vuejs/vue/tree/dev/dist
# I got this handy makefile syntax from : https://github.com/mandel59/sqlite-wasm (MIT License) Credited in LICENSE
# To use another version of Sqlite, visit https://www.sqlite.org/download.html and copy the appropriate values here:
SQLITE_AMALGAMATION = sqlite-amalgamation-3320000
SQLITE_AMALGAMATION_ZIP_URL = https://www.sqlite.org/2020/sqlite-amalgamation-3320000.zip
SQLITE_AMALGAMATION_ZIP_SHA1 = b55939b50d277aa1146f91a76bf9de200942f5d3
# Note that extension-functions.c hasn't been updated since 2010-02-06, so likely doesn't need to be updated
EXTENSION_FUNCTIONS = extension-functions.c
EXTENSION_FUNCTIONS_URL = https://www.sqlite.org/contrib/download/extension-functions.c?get=25
EXTENSION_FUNCTIONS_SHA1 = c68fa706d6d9ff98608044c00212473f9c14892f
EMCC=emcc
CFLAGS = \
-O2 \
-DSQLITE_OMIT_LOAD_EXTENSION \
-DSQLITE_DISABLE_LFS \
-DSQLITE_ENABLE_FTS3 \
-DSQLITE_ENABLE_FTS3_PARENTHESIS \
-DSQLITE_THREADSAFE=0
# When compiling to WASM, enabling memory-growth is not expected to make much of an impact, so we enable it for all builds
# Since tihs is a library and not a standalone executable, we don't want to catch unhandled Node process exceptions
# So, we do : `NODEJS_CATCH_EXIT=0`, which fixes issue: https://github.com/sql-js/sql.js/issues/173 and https://github.com/sql-js/sql.js/issues/262
EMFLAGS = \
--memory-init-file 0 \
-s RESERVED_FUNCTION_POINTERS=64 \
-s ALLOW_TABLE_GROWTH=1 \
-s EXPORTED_FUNCTIONS=@src/exported_functions.json \
-s EXTRA_EXPORTED_RUNTIME_METHODS=@src/exported_runtime_methods.json \
-s SINGLE_FILE=0 \
-s NODEJS_CATCH_EXIT=0
EMFLAGS_ASM = \
-s WASM=0
EMFLAGS_ASM_MEMORY_GROWTH = \
-s WASM=0 \
-s ALLOW_MEMORY_GROWTH=1
EMFLAGS_WASM = \
-s WASM=1 \
-s ALLOW_MEMORY_GROWTH=1
EMFLAGS_OPTIMIZED= \
-s INLINING_LIMIT=50 \
-O3 \
-flto \
--llvm-lto 1 \
--closure 1
EMFLAGS_DEBUG = \
-s INLINING_LIMIT=10 \
-s ASSERTIONS=1 \
-O1
BITCODE_FILES = out/sqlite3.bc out/extension-functions.bc
OUTPUT_WRAPPER_FILES = src/shell-pre.js src/shell-post.js
SOURCE_API_FILES = src/api.js
EMFLAGS_PRE_JS_FILES = \
--pre-js src/api.js
EXPORTED_METHODS_JSON_FILES = src/exported_functions.json src/exported_runtime_methods.json
all: optimized debug worker
.PHONY: debug
debug: dist/sql-asm-debug.js dist/sql-wasm-debug.js
dist/sql-asm-debug.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(SOURCE_API_FILES) $(EXPORTED_METHODS_JSON_FILES)
$(EMCC) $(EMFLAGS) $(EMFLAGS_DEBUG) $(EMFLAGS_ASM) $(BITCODE_FILES) $(EMFLAGS_PRE_JS_FILES) -o $@
mv $@ out/tmp-raw.js
cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@
rm out/tmp-raw.js
dist/sql-wasm-debug.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(SOURCE_API_FILES) $(EXPORTED_METHODS_JSON_FILES)
$(EMCC) $(EMFLAGS) $(EMFLAGS_DEBUG) $(EMFLAGS_WASM) $(BITCODE_FILES) $(EMFLAGS_PRE_JS_FILES) -o $@
mv $@ out/tmp-raw.js
cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@
rm out/tmp-raw.js
.PHONY: optimized
optimized: dist/sql-asm.js dist/sql-wasm.js dist/sql-asm-memory-growth.js
dist/sql-asm.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(SOURCE_API_FILES) $(EXPORTED_METHODS_JSON_FILES)
$(EMCC) $(EMFLAGS) $(EMFLAGS_OPTIMIZED) $(EMFLAGS_ASM) $(BITCODE_FILES) $(EMFLAGS_PRE_JS_FILES) -o $@
mv $@ out/tmp-raw.js
cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@
rm out/tmp-raw.js
dist/sql-wasm.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(SOURCE_API_FILES) $(EXPORTED_METHODS_JSON_FILES)
$(EMCC) $(EMFLAGS) $(EMFLAGS_OPTIMIZED) $(EMFLAGS_WASM) $(BITCODE_FILES) $(EMFLAGS_PRE_JS_FILES) -o $@
mv $@ out/tmp-raw.js
cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@
rm out/tmp-raw.js
dist/sql-asm-memory-growth.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) $(SOURCE_API_FILES) $(EXPORTED_METHODS_JSON_FILES)
$(EMCC) $(EMFLAGS) $(EMFLAGS_OPTIMIZED) $(EMFLAGS_ASM_MEMORY_GROWTH) $(BITCODE_FILES) $(EMFLAGS_PRE_JS_FILES) -o $@
mv $@ out/tmp-raw.js
cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@
rm out/tmp-raw.js
# Web worker API
.PHONY: worker
worker: dist/worker.sql-asm.js dist/worker.sql-asm-debug.js dist/worker.sql-wasm.js dist/worker.sql-wasm-debug.js
dist/worker.sql-asm.js: dist/sql-asm.js src/worker.js
cat $^ > $@
dist/worker.sql-asm-debug.js: dist/sql-asm-debug.js src/worker.js
cat $^ > $@
dist/worker.sql-wasm.js: dist/sql-wasm.js src/worker.js
cat $^ > $@
dist/worker.sql-wasm-debug.js: dist/sql-wasm-debug.js src/worker.js
cat $^ > $@
# Building it this way gets us a wrapper that _knows_ it's in worker mode, which is nice.
# However, since we can't tell emcc that we don't need the wasm generated, and just want the wrapper, we have to pay to have the .wasm generated
# even though we would have already generated it with our sql-wasm.js target above.
# This would be made easier if this is implemented: https://github.com/emscripten-core/emscripten/issues/8506
# dist/worker.sql-wasm.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) src/api.js src/worker.js $(EXPORTED_METHODS_JSON_FILES) dist/sql-wasm-debug.wasm
# $(EMCC) $(EMFLAGS) $(EMFLAGS_OPTIMIZED) -s ENVIRONMENT=worker -s $(EMFLAGS_WASM) $(BITCODE_FILES) --pre-js src/api.js -o out/sql-wasm.js
# mv out/sql-wasm.js out/tmp-raw.js
# cat src/shell-pre.js out/tmp-raw.js src/shell-post.js src/worker.js > $@
# #mv out/sql-wasm.wasm dist/sql-wasm.wasm
# rm out/tmp-raw.js
# dist/worker.sql-wasm-debug.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) src/api.js src/worker.js $(EXPORTED_METHODS_JSON_FILES) dist/sql-wasm-debug.wasm
# $(EMCC) -s ENVIRONMENT=worker $(EMFLAGS) $(EMFLAGS_DEBUG) -s ENVIRONMENT=worker -s WASM_BINARY_FILE=sql-wasm-foo.debug $(EMFLAGS_WASM) $(BITCODE_FILES) --pre-js src/api.js -o out/sql-wasm-debug.js
# mv out/sql-wasm-debug.js out/tmp-raw.js
# cat src/shell-pre.js out/tmp-raw.js src/shell-post.js src/worker.js > $@
# #mv out/sql-wasm-debug.wasm dist/sql-wasm-debug.wasm
# rm out/tmp-raw.js
out/sqlite3.bc: sqlite-src/$(SQLITE_AMALGAMATION)
mkdir -p out
# Generate llvm bitcode
$(EMCC) $(CFLAGS) -c sqlite-src/$(SQLITE_AMALGAMATION)/sqlite3.c -o $@
out/extension-functions.bc: sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTIONS)
mkdir -p out
$(EMCC) $(CFLAGS) -s LINKABLE=1 -c sqlite-src/$(SQLITE_AMALGAMATION)/extension-functions.c -o $@
# TODO: This target appears to be unused. If we re-instatate it, we'll need to add more files inside of the JS folder
# module.tar.gz: test package.json AUTHORS README.md dist/sql-asm.js
# tar --create --gzip $^ > $@
## cache
cache/$(SQLITE_AMALGAMATION).zip:
mkdir -p cache
curl -LsSf '$(SQLITE_AMALGAMATION_ZIP_URL)' -o $@
cache/$(EXTENSION_FUNCTIONS):
mkdir -p cache
curl -LsSf '$(EXTENSION_FUNCTIONS_URL)' -o $@
## sqlite-src
.PHONY: sqlite-src
sqlite-src: sqlite-src/$(SQLITE_AMALGAMATION) sqlite-src/$(EXTENSION_FUNCTIONS)
sqlite-src/$(SQLITE_AMALGAMATION): cache/$(SQLITE_AMALGAMATION).zip
mkdir -p sqlite-src
echo '$(SQLITE_AMALGAMATION_ZIP_SHA1) ./cache/$(SQLITE_AMALGAMATION).zip' > cache/check.txt
sha1sum -c cache/check.txt
rm -rf $@
unzip -u 'cache/$(SQLITE_AMALGAMATION).zip' -d sqlite-src/
touch $@
sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTIONS): cache/$(EXTENSION_FUNCTIONS)