-
-
Save devinrhode2/6006131 to your computer and use it in GitHub Desktop.
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
data:text/html, | |
<body id='b'> | |
<textarea spellcheck="false" id="t" autofocus></textarea> | |
<script> | |
var f, | |
t = document.getElementById("t"), | |
b = document.body, | |
v = t.value, | |
c = parseInt(b.getAttribute("c")) || t.value.length, | |
s = parseInt(b.getAttribute("s")) || 0; | |
document.title = t.value.split("\n")[0] || "..."; | |
t.className = "s"; | |
t.scrollTop = s; | |
function updateUrl() { | |
clearInterval(f); | |
f = setTimeout(function() { | |
if (v === t.value) { return false; } | |
t.className = ""; | |
t.innerHTML = encodeURIComponent(t.value); | |
var s = "data:text/html,<body id='b'"; | |
if (!!t.selectionStart) { s += " c='" + t.selectionStart + "'"; } | |
s += " s='" + t.scrollTop + "'>" + b.innerHTML; | |
window.location.href = s; | |
}, 500); | |
} | |
t.addEventListener("keyup", updateUrl); | |
if (!!t.setSelectionRange) { | |
t.setSelectionRange(c,c); | |
setTimeout(function(){ | |
t.setSelectionRange(c,c); | |
t.scrollTop = s; | |
}, 10); | |
} | |
</script> | |
<style> | |
textarea { | |
position: fixed; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
overflow: auto; | |
margin: 0; | |
padding: 10px; | |
background: black; | |
font: 14px/20px monospace; | |
outline: none; | |
border: none; | |
box-sizing: border-box; | |
cursor: wait; | |
color: gray; | |
} | |
textarea.s { | |
cursor: text; | |
color: white; | |
} | |
</style> | |
<!-- http://iamnotagoodartist.com/web/an-auto-updating-data-uri-text-editor --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment