diff --git a/js/babycode-editor.js b/js/babycode-editor.js index 7cffcfb..5247e83 100644 --- a/js/babycode-editor.js +++ b/js/babycode-editor.js @@ -8,6 +8,24 @@ } }) + const inThread = () => { + const scheme = window.location.pathname.split("/"); + return scheme[1] === "threads" && scheme[2] !== "create"; + } + + ta.addEventListener("input", () => { + if (!inThread()) return; + + localStorage.setItem(window.location.pathname, ta.value); + }) + + document.addEventListener("DOMContentLoaded", () => { + if (!inThread()) return; + const prevContent = localStorage.getItem(window.location.pathname); + if (!prevContent) return; + ta.value = prevContent; + }) + const buttonBold = document.getElementById("post-editor-bold"); const buttonItalics = document.getElementById("post-editor-italics"); const buttonStrike = document.getElementById("post-editor-strike");