Commit f929d057 authored by Clara Stoddart's avatar Clara Stoddart

Adding background script

parent e547647c
......@@ -4,6 +4,10 @@ var srcName;
var dietNum = 0;
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);
}
......@@ -20,9 +24,8 @@ function checkAllergen(product) {
xhr.onerror = () => reject(xhr.status);
xhr.open("GET", "http://localhost/script.php?product="+product+"&dietNum="+2, true);
xhr.send();
});
return promise;
});
return promise;
}
document.addEventListener('mousemove', function (e) {
......@@ -30,27 +33,27 @@ document.addEventListener('mousemove', function (e) {
if (srcElement.nodeName == 'IMG') {
srcName = srcElement.alt;
promise = checkAllergen(srcName).then(
function(responseText) {
console.log("Success");
if (responseText == "1" || responseText == undefined) {
srcElement.classList.add(MOUSE_VISITED_CLASSNAME);
} else if (responseText == "0") {
srcElement.classList.add(MOUSE_VISITED_CLASSNAME_FALSE);
}
},
function(failureStatus) {
console.log(failureStatus);
if (failureStatus == 0) {
console.log("Not in database");
}
});
console.info(srcElement.currentSrc);
console.dir(srcElement);
}
}, false);
if(document){
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("Submit").addEventListener("click", dietNumInit);
});
}
\ No newline at end of file
function(responseText) {
console.log("Success");
if (responseText == "1" || responseText == undefined) {
srcElement.classList.add(MOUSE_VISITED_CLASSNAME);
} else if (responseText == "0") {
srcElement.classList.add(MOUSE_VISITED_CLASSNAME_FALSE);
}
},
function(failureStatus) {
console.log(failureStatus);
if (failureStatus == 0) {
console.log("Not in database");
}
});
console.info(srcElement.currentSrc);
console.dir(srcElement);
}
}, false);
if (document) {
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("Submit").addEventListener("click", dietNumInit);
});
}
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