1var saveTimeoutId;
2
3document.addEventListener("DOMContentLoaded", () => {
4 // Get the element(s) you want to autosave
5 let area = document.getElementById('area');
6
7 // use keyup over keypress so that backspaces will register
8 area.addEventListener('keyup', () =>{
9
10 // clear save timeout as the user is editing
11 if (saveTimeoutId) window.clearTimeout(saveTimeoutId);
12
13 // Store the timeout id again
14 saveTimeoutId = window.setTimeout(() =>{
15 ...
16 // Code for saving here
17 ...
18 }, 1000); // Configure timeout period to preference
19 });
20
21});