I spend too much time in the terminal and have developed the annoying habit of pressing Ctrl-W to remove the last word I typed in. So, naturally, I did it while typing in my devlog and all the content was lost.
I did some digging around and, in general, this feature is as simple as:
addEventListener("beforeunload", () => {
if (/* there is some text in the text area */) {
event.preventDefault();
}
});
It displays a neat browser-defined window that asks if you meant to leave the page.
Would be nice to have it for every page where the content can potentially be lost while closing the page. Of course, it would help anyone who can potentially close the window without meaning to, not just nerds with weird habits. :)