diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-09-20 21:12:47 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-09-20 21:12:47 -0700 |
| commit | 1905b90698b8171880b812bec1fcafaf0e35dc6a (patch) | |
| tree | d676478bde0005179244c6baf06bdfb0b847c0c1 /static/note.js | |
| parent | 34a2a69a28457f5b58c357cb19f091330cca6110 (diff) | |
| download | roseh.moe-1905b90698b8171880b812bec1fcafaf0e35dc6a.tar.zst | |
Ditch HTMX
Diffstat (limited to 'static/note.js')
| -rw-r--r-- | static/note.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/static/note.js b/static/note.js new file mode 100644 index 0000000..27d3eef --- /dev/null +++ b/static/note.js @@ -0,0 +1,39 @@ +let running = false; +let pending = false; + +async function save() { + if (running) { + pending = true; + return; + } + running = true; + + try { + const indicator = document.getElementById("save-indicator"); + indicator.innerHTML = "Saving..."; + indicator.classList.remove("hidden"); + + let responseHTML; + do { + pending = false; + const response = await fetch("/notepad/autosave", { + method: "POST", + body: new FormData(document.getElementById("form")), + }); + responseHTML = await response.text(); + } while (pending); + // Who needs HTMX? + document.getElementById("save-indicator-wrapper").innerHTML = responseHTML; + } finally { + running = false; + } +} + +let autosaveTimer; + +function autosave(key) { + document.getElementById("save-indicator").classList.add("hidden"); + + clearTimeout(autosaveTimer); + autosaveTimer = setTimeout(() => save(key), 1000); +} |
