diff options
author | JoelHMikael <joel.h.kronqvist@gmail.com> | 2021-12-06 14:59:09 +0200 |
---|---|---|
committer | JoelHMikael <joel.h.kronqvist@gmail.com> | 2021-12-06 14:59:09 +0200 |
commit | fbfdfaec51be5a7ead56a2888e4864c8b3470db5 (patch) | |
tree | cc6e294b037f534761afaf34a40b341011f862d8 /server.js | |
parent | ffef8333636fe6143aa675534f6ce7852199be20 (diff) | |
download | LYLLRuoka-fbfdfaec51be5a7ead56a2888e4864c8b3470db5.tar.gz LYLLRuoka-fbfdfaec51be5a7ead56a2888e4864c8b3470db5.zip |
Added a possibility to choose the weekday
Diffstat (limited to 'server.js')
-rw-r--r-- | server.js | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -80,11 +80,14 @@ async function buildMain(args) const DB = args["db"]; const data = await openFile(path); - const data_string = data.toString("utf-8"); - let res; + let data_string = data.toString("utf-8"); + let res; const d = new Date(); - const day = d.getDay(); + let day = d.getDay(); + + if ((typeof query.day === "string") && (parseInt(query.day).toString() === query.day) && (!isNaN(parseInt(query.day))) && (parseInt(query.day) > 0) && (parseInt(query.day) < 7)) + day = parseInt(query.day); if ((day === 0) || (day === 6)) res = `Maanantain ruoka: ${parse.get(day, query.index, DB)}`; @@ -95,7 +98,10 @@ async function buildMain(args) if (res === -1) res = "Kyseiselle kurssille/opettajalle ei löydy ruokailua päivältä!"; - return data_string.replace("\\(result\\)", res); + data_string = data_string.replace("\\(result\\)", res); + data_string = data_string.replace(`<option value=\"${day}\">`, `<option value=\"${day}\" selected>`); + + return data_string; } async function build404(path, attemptpath) |