function debounce(func, wait, immediate) { var timeout; return function() { var context = this, args = arguments; var later = function() { timeout = null; if (!immediate) func.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; }; const localUpload = (e) => { console.log(e.target.innerHTML); window.localStorage.setItem("bodyText", e.target.innerHTML); } const debouncedUpload = debounce(localUpload, 200); document .querySelectorAll('[data-tiny-editor]') .forEach(editor => editor.addEventListener('input', debouncedUpload) ) //load the local storage const bodyText = window.localStorage.getItem("bodyText"); if (bodyText === null) { document.querySelector('[data-tiny-editor]').innerHTML = "This is solo mode. Changes are only made locally and are 100% private" } else { document.querySelector('[data-tiny-editor]').innerHTML = bodyText; }