Last active
July 14, 2017 06:38
-
-
Save rjcorwin/966525c209402320931dfd8b04dfd997 to your computer and use it in GitHub Desktop.
A document that live edits itself for all those beaker browsers watching it with live reloading turned on.
This file contains 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
<html id="content"> | |
<head> | |
<script> | |
var selfArchive = new DatArchive('' + window.location) | |
var state = (document.getElementById('content')).outerHTML | |
// Counter for the number of state changes thus commits. | |
var i = 0 | |
async function saveIt() { | |
// Check if state is stale. | |
if (state !== (document.getElementById('content')).outerHTML) { | |
state = (document.getElementById('content')).outerHTML | |
await selfArchive.writeFile('/index.html', state, 'utf8') | |
console.log('write') | |
await selfArchive.commit() | |
console.log('commit') | |
i++ | |
console.log(i) | |
} | |
// Debounce as to not overload network on very fast key strokes. | |
setTimeout(saveIt, 500) | |
} | |
saveIt() | |
</script> | |
</head> | |
<body> | |
<div contenteditable="true">click here to edit</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment