Skip to content

Instantly share code, notes, and snippets.

@dankantor
Created August 29, 2018 19:40
Show Gist options
  • Save dankantor/4ec93e64c85c65013ac95d6fe1909ca4 to your computer and use it in GitHub Desktop.
Save dankantor/4ec93e64c85c65013ac95d6fe1909ca4 to your computer and use it in GitHub Desktop.
Save notes to localStorage
<html>
<head></head>
<body>
<div id="c" contenteditable style="min-height:300px;outline:none;"></div>
<script type="text/javascript">
let div = document.querySelector('#c');
let timeout;
let ls = localStorage.getItem('text') || '';
ls = '<br><br>' + ls;
div.innerHTML = ls;
div.focus();
div.addEventListener('keyup', (e) => {
clearTimeout(timeout);
timeout = setTimeout(() => {
let text = div.innerHTML;
localStorage.setItem('text', text);
}, 500);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment