diff --git a/public/javascripts/index.js b/public/javascripts/index.js new file mode 100644 index 0000000..bcaed19 --- /dev/null +++ b/public/javascripts/index.js @@ -0,0 +1,32 @@ +const commandAction = document.getElementById("command-action"); +const addButton = document.getElementById("add-command"); +const rmButton = document.getElementById("remove-command"); + +function lastCommandId() { + let list = document.querySelectorAll("div.command h2"); + return parseInt(list[list.length-1].innerText.replace("Command ", "")); +} + +addButton.addEventListener("click", () => { + let id = lastCommandId() + 1; + commandAction.insertAdjacentHTML("beforebegin", `
+

Command ${id}

+
+ + +
+
+ + +
+
`); + document.getElementById("command"+lastCommandId()).scrollIntoView({behavior: "smooth"}); + rmButton.classList.remove("hide"); +}); + +rmButton.addEventListener("click", () => { + let id = lastCommandId(); + document.getElementById("command"+id).remove(); + if (id === 2) + rmButton.classList.add("hide"); +}); diff --git a/routes/command.js b/routes/command.js new file mode 100644 index 0000000..ae7b5dd --- /dev/null +++ b/routes/command.js @@ -0,0 +1,9 @@ +let express = require("express"); +let router = express.Router(); + +/* GET home page. */ +router.post("/", (req, res) => { + console.log(req.body); +}); + +module.exports = router;