diff --git a/app.js b/app.js
index 7b6348c..86967a9 100644
--- a/app.js
+++ b/app.js
@@ -194,8 +194,12 @@ function server() {
})
app.get("/stats", (req, res) => {
- let rawStatsFile = fs.readFileSync(statsPath)
- res.json(JSON.parse(rawStatsFile))
+ if (fs.existsSync(statsPath)) {
+ let rawStatsFile = fs.readFileSync(statsPath)
+ res.json(JSON.parse(rawStatsFile))
+ } else {
+ res.json(stats)
+ }
})
app.get("/winner", (req, res) => {
diff --git a/assets/js/main.js b/assets/js/main.js
index 852bc60..becb0ec 100644
--- a/assets/js/main.js
+++ b/assets/js/main.js
@@ -7,7 +7,7 @@ function autocomplete(inp, arr) {
the text field element and an array of possible autocompleted values:*/
var currentFocus;
/*execute a function when someone writes in the text field:*/
- inp.addEventListener("input", function (e) {
+ inp.addEventListener("input", function () {
var a, b, i, val = this.value;
/*close any already open lists of autocompleted values*/
closeAllLists();
@@ -24,9 +24,9 @@ function autocomplete(inp, arr) {
let s1 = arr[i].split(" ")[0]
let s2 = arr[i].split(" ")[1]
/*check if the item starts with the same letters as the text field value:*/
- if (s1.substr(0, val.length).toUpperCase() == val.toUpperCase() || s2.substr(0, val.length).toUpperCase() == val.toUpperCase() || arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {
- let first = s1.substr(0, val.length).toUpperCase() == val.toUpperCase()
- let second = s2.substr(0, val.length).toUpperCase() == val.toUpperCase()
+ if (s1.substr(0, val.length).toUpperCase() === val.toUpperCase() || s2.substr(0, val.length).toUpperCase() === val.toUpperCase() || arr[i].substr(0, val.length).toUpperCase() === val.toUpperCase()) {
+ let first = s1.substr(0, val.length).toUpperCase() === val.toUpperCase()
+ let second = s2.substr(0, val.length).toUpperCase() === val.toUpperCase()
/*create a DIV element for each matching element:*/
b = document.createElement("DIV");
/*make the matching letters bold:*/
@@ -42,7 +42,7 @@ function autocomplete(inp, arr) {
/*insert a input field that will hold the current array item's value:*/
b.innerHTML += "";
/*execute a function when someone clicks on the item value (DIV element):*/
- b.addEventListener("click", function (e) {
+ b.addEventListener("click", function () {
/*insert the value for the autocomplete text field:*/
inp.value = this.getElementsByTagName("input")[0].value;
/*close the list of autocompleted values,
@@ -58,19 +58,19 @@ function autocomplete(inp, arr) {
inp.addEventListener("keydown", function (e) {
var x = document.getElementById(this.id + "autocomplete-list");
if (x) x = x.getElementsByTagName("div");
- if (e.keyCode == 40) {
+ if (e.keyCode === 40) {
/*If the arrow DOWN key is pressed,
increase the currentFocus variable:*/
currentFocus++;
/*and and make the current item more visible:*/
addActive(x);
- } else if (e.keyCode == 38) { //up
+ } else if (e.keyCode === 38) { //up
/*If the arrow UP key is pressed,
decrease the currentFocus variable:*/
currentFocus--;
/*and and make the current item more visible:*/
addActive(x);
- } else if (e.keyCode == 13) {
+ } else if (e.keyCode === 13) {
/*If the ENTER key is pressed, prevent the form from being submitted,*/
e.preventDefault();
if (currentFocus > -1) {
@@ -100,7 +100,7 @@ function autocomplete(inp, arr) {
except the one passed as an argument:*/
var x = document.getElementsByClassName("autocomplete-items");
for (var i = 0; i < x.length; i++) {
- if (elmnt != x[i] && elmnt != inp) {
+ if (elmnt !== x[i] && elmnt !== inp) {
x[i].parentNode.removeChild(x[i]);
}
}
@@ -121,8 +121,14 @@ document.addEventListener("keyup", async function (event) {
});
function enter() {
+ let utc = new Date()
+ let d = new Date(Date.UTC(utc.getUTCFullYear(), utc.getUTCMonth(), utc.getUTCDate(), 0, 0, 0))
+ let expire = new Date(JSON.parse(localStorage.guesses)[0])
+ if (expire <= d) {
+ location.reload()
+ }
let value = document.getElementById("myInput").value
- if (value != "") {
+ if (value !== "") {
let potential = 0
let lower = 0
let top = 0
@@ -137,7 +143,7 @@ function enter() {
}
})
- if (potential == 1 || document.getElementsByClassName("autocomplete-items")[0].children.length == 1 && value.replace(/[0-9]/g, '') != "") {
+ if (potential === 1 || document.getElementsByClassName("autocomplete-items")[0].children.length === 1 && value.replace(/[0-9]/g, '') !== "") {
if (localStorage.guesses == null) {
let d = new Date()
localStorage.guesses = JSON.stringify([new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate() + 1, 0, 0, 0)), guess])
@@ -175,15 +181,15 @@ function pulse() {
async function submit(guess, real) {
localStorage.first = false
- return new Promise(async (res, rej) => {
+ return new Promise(async (res) => {
let obj = {}
Object.entries(driversObj).forEach(driver => {
- if (driver[1].firstName + " " + driver[1].lastName == guess) obj = driver[1]
+ if (driver[1].firstName + " " + driver[1].lastName === guess) obj = driver[1]
})
- let frames = Array.from(document.getElementsByClassName("frame")).filter(x => x.childNodes.length == 0)
+ let frames = Array.from(document.getElementsByClassName("frame")).filter(x => x.childNodes.length === 0)
frames[0].innerHTML = `