Skip to content

Instantly share code, notes, and snippets.

@vincentorback
Last active May 8, 2017 12:30
Show Gist options
  • Save vincentorback/7efbf71d980d45aab398 to your computer and use it in GitHub Desktop.
Save vincentorback/7efbf71d980d45aab398 to your computer and use it in GitHub Desktop.
Simple writing in the browser
Paste this into your browser:
data:text/html,<html><head><title>Just write!</title><style>*{margin: 0 padding: 0}body{width: 90%; max-width: 650px; margin: 5% auto;}@media (min-width:800px){body{font-size: 2em;}}</style><script>var body=document.body if(localStorage.justWrite) body.innerHTML=localStorage.justWrite} function downloadInnerHtml(filename,mimeType){var elHtml=body.innerHTML var link=document.createElement('a') mimeType=mimeType||'text/plain' filename=filename||'document.txt' link.setAttribute('download',filename) link.setAttribute('href','data:'+mimeType+'charset=utf-8,'+encodeURIComponent(elHtml)) link.click()} window.onkeydown=function(event){if((event.key===83)&&(event.metaKey||event.ctrlKey)){downloadInnerHtml() e.preventDefault() return false} localStorage.justWrite=body.innerHTML}</script></head><body contenteditable></body></html>
<!--
TODO:
- CMD + S to save file. ✓
- Auto focus on input
- Choose file extension .md, .txt, .doc
- Name save file
- Save in localstorage as you write
-->
data:text/html,
<html>
<head>
<title>Just write!</title>
<style>
* {
margin: 0;
padding: 0;
}
body{
width: 90%;
max-width: 650px;
margin: 5% auto;
}
@media (min-width:800px) {
body {
font-size: 2em;
}
}
</style>
<script>
var body = document.body
if (window.localStorage.justWrite) {
body.innerHTML = window.localStorage.justWrite
}
function downloadInnerHtml (filename, mimeType) {
var link = document.createElement('a')
mimeType = mimeType || 'text/plain'
filename = filename || 'document.txt'
link.setAttribute('download', filename)
link.setAttribute('href', 'data:' + mimeType + 'charset=utf-8,' + encodeURIComponent(body.innerHTML))
link.click()
}
window.onkeydown = function (event) {
if ((event.key === 83) && (event.metaKey || event.ctrlKey)) {
downloadInnerHtml()
event.preventDefault()
return false
}
window.localStorage.justWrite = body.innerHTML
}
</script>
</head>
<body contenteditable></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment