Last active
March 19, 2025 18:34
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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