git init m8
This commit is contained in:
commit
a5c4ffe3e9
5 changed files with 272 additions and 0 deletions
37
static/note.js
Normal file
37
static/note.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
const textarea = document.getElementById("editor");
|
||||
const status = document.getElementById("status");
|
||||
|
||||
fetch("/api/" + noteName)
|
||||
.then(res => res.ok ? res.text() : "")
|
||||
.then(text => {
|
||||
textarea.value = text;
|
||||
status.textContent = "Loaded";
|
||||
});
|
||||
|
||||
let timeout;
|
||||
let last = "";
|
||||
|
||||
textarea.addEventListener("input", () => {
|
||||
status.textContent = "Typing...";
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
const text = textarea.value;
|
||||
if (text !== last) {
|
||||
fetch("/api/" + noteName, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ content: text })
|
||||
}).then(res => {
|
||||
if (res.ok) {
|
||||
last = text;
|
||||
status.textContent = "Saved";
|
||||
} else {
|
||||
status.textContent = "Save failed";
|
||||
}
|
||||
});
|
||||
} else {
|
||||
status.textContent = "No changes";
|
||||
}
|
||||
}, 500);
|
||||
});
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue