Skip to content

Instantly share code, notes, and snippets.

@sverweij
Last active March 19, 2025 18:34
Show Gist options
  • Save sverweij/188bfd227f1a2e0e1694c676d7bc192b to your computer and use it in GitHub Desktop.
Save sverweij/188bfd227f1a2e0e1694c676d7bc192b to your computer and use it in GitHub Desktop.
Local html that saves its own content to local storage (e.g. use as a scratch shortcut in the bookmarks bar)
<!DOCTYPE html>
<html>
<head>   
<title>SCRATCH</title>   
<script>
window.onload = () => {
const content = document.querySelector('[contenteditable]');
if (localStorage.getItem('scratch.savedContent')) {
content.innerHTML = localStorage.getItem('scratch.savedContent');
}
content.addEventListener('input', () => {
localStorage.setItem('scratch.savedContent', content.innerHTML);
});
}   
</script>
</head>
<body contenteditable style="font: 1rem/1 monospace; line-height: 1.4rem; max-width: 60rem; margin: 0 auto; padding: 4rem; color: darkblue; background-color: lightyellow"></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment