aboutsummaryrefslogtreecommitdiff
path: root/secrets/public/script.js
diff options
context:
space:
mode:
authorMarvin Borner2021-01-29 21:14:36 +0100
committerMarvin Borner2021-01-29 21:14:36 +0100
commitb5058eb7ff8c110bc24a64d02bc42e0a9dc267f5 (patch)
tree44dc8b82fb9f6f254c001b4800f8efc9654b7847 /secrets/public/script.js
parentf9ccf6ed47254edf7c1fb6231212bd4b4d6c8356 (diff)
It's no secret that our code is a mess
Diffstat (limited to 'secrets/public/script.js')
-rw-r--r--secrets/public/script.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/secrets/public/script.js b/secrets/public/script.js
new file mode 100644
index 0000000..881df3a
--- /dev/null
+++ b/secrets/public/script.js
@@ -0,0 +1,27 @@
+const list = document.getElementById("list");
+
+function appendsecret(response) {
+ response.forEach((elem) => {
+ list.insertAdjacentHTML(
+ "beforeend",
+ `<li><span class="text">${elem["secret"]}</span>${
+ elem["owner"] ? ' <span class="delete-btn" data-id="' + elem["id"] + '"></span></li><hr>' : ""
+ }`,
+ );
+
+ const span = document.querySelector(`li span[data-id="${elem["id"]}"]`);
+ if (span)
+ span.addEventListener("click", (event) => {
+ if (!confirm("Bist du dir sicher, dass du das Zitat löschen willst?")) return;
+ fetch("api/delete/" + event.target.getAttribute("data-id"), { method: "DELETE" })
+ .then((response) => response.text())
+ .then((response) => {
+ if (response == "ok") event.target.parentNode.remove();
+ });
+ });
+ });
+}
+
+fetch("api/list")
+ .then((response) => response.json())
+ .then((response) => appendsecret(response));