Last active
October 8, 2024 04:51
-
-
Save myfonj/c8ce74bf549e19600026ce9022388df8 to your computer and use it in GitHub Desktop.
HTML sandbox - editor in data URI 1176 b, with live preview and persistence.
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;charset=utf-8;verbatim,<!doctype html><html style="color-scheme:dark light"><title>HTML sandbox 2.0.6</title><meta name=viewport content=width=device-width,initial-scale=1><body style=margin:0;display:flex;height:100vh onload="OT=(DC=document).title,H=(L=location).hash.slice(1)||'',RX=/(^data:.+?(;verbatim)?,)?([^]*)/,A.value=H.match(RX)[2]?H:decodeURIComponent(H)||A.value;T=W=0;E=RegExp('^'+(D='data:text/html;charset=utf-8,'));F=()=>{if(W!=(V=A.value))W=V,M=V.match(RX),I.src=M[2]?V:(M[1]||D)+encodeURIComponent(M[3]),DC.title=NT=((TM=V.match(/<title\b[^]*?\x3E([^]*?)<\/title\b/m))&&(NT=TM[1])&&(NT=NT.trim())&&(DC.title=NT+' @ '+OT))||OT};F()"><textarea autocapitalize=off style=resize:horizontal;width:50vw autofocus id=A onkeyup=clearTimeout(T);T=setTimeout(F,400) onblur=try{history.pushState({},NT,'\u0023'+(S=I.src.replace(E,'')))}catch(e){L.hash=S}><!doctype html><html lang="en" style="color-scheme: dark light;">%0A<meta name="viewport" content="width=device-width, initial-scale=1">%0A<title>%0A%0A</title>%0A<style>%0A%0A</style>%0A<body>%0A%s%0A<script>%0A%0A</script>%0A</textarea><iframe style=border:0;flex-grow:1;width:0 id=I> |
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;charset=utf-8,<title>HTML sandbox 1.1.4</title><meta name=viewport content=width=device-width,initial-scale=1><body style=margin:0;display:flex;height:100vh;background:black onload="OT=(DC=document).title,A.value=decodeURIComponent((L=location).hash.slice(1)||'');T=W=0;E=RegExp('^'+(D='data:text/html;charset=utf-8,'));F=()=>{if(W!=(V=A.value))W=V,M=V.match(/(^data:.+?,)?([^]*)/),I.src=M[1]?V:D+encodeURIComponent(M[2]),DC.title=NT=((TM=V.match(/<title\b[^]*?\x3E([^]*?)<\/title\b/m))&&(NT=TM[1])&&(NT=NT.trim())&&(DC.title=NT+' @ '+OT))||OT};F()"><textarea style=resize:horizontal;width:50vw;border:inset;opacity:.7;color:snow;background:transparent autofocus id=A onkeyup=clearTimeout(T);T=setTimeout(F,400) onblur=try{history.pushState({},NT,'\u0023'+(S=I.src.replace(E,'')))}catch(e){L.hash=S}></textarea><iframe style=flex-grow:1;width:0;border:0;background:grey id=I>#%3C!doctype html%3E%3Chtml lang%3D""%3E%3Ctitle%3E%0A%0A%3C%2Ftitle%3E%0A%3Cmeta name%3D"viewport" content%3D"width%3Ddevice-width%2C initial-scale%3D1"%3E%0A%3Cstyle%3E%0A%3Aroot %7B background%3A dimgray%3B color%3A snow%3B %7D%0A%3Alink %7B color%3A aqua%3B %7D %3Avisited %7B color%3A lime%3B %7D%0A%0A%3C%2Fstyle%3E%0A%3Cbody%3E%0A%0A%3Cscript%3E%0A%0A%3C%2Fscript%3E%0A |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Changelog
embed
back toiframe
: embed is OK on Firefox, but behaves strangely in Chrome: sometimes not rendered until inspected with devtools. Heisenbug, maybe worth investigating.iframe
forembed
, since it seems there is no difference for this purpose. And its shorter (no style to alter) and even "valid" (void, no closing tag needed). Also removed the inset styling of the textarea.;verbatim
(erroneous decode when restored); bloated few bytes backcolor-scheme="dark"
(must be present in document as well); • made "verbatim" mode derived from explicit;verbatim,
in datauri prologue instead of sole prologue presence; • possibility to have default content even when used as physical file.Features
live preview
text/html
(text/html;charset=utf-8,
)data:application/xhtml+xml,
/data:image/svg+xml,
/data:text/plain,
%XX
escapes."Verbatim" mode
;verbatim,
in prefix to have plain non-encoded readable value in the hash (or more precisely, leave it on the browser)#
=%23
;%
=%25
; line break =%0A
.Persistence (bookmark-ability and keyword-searchability)
#hash
after editor blur event%s
in bookmark URL for query substitutionA
, URL ends with#<b>%s</b>
enteringA bar
in URLbar will produce<b>bar</b>
in editor%s
sequence inside<body>
, so when bookmarked this way you'll get the content in there; moving%s
from the middle to the end after added#
would make it work so the boilerplate would be used without keyword search argument and when argument supplied, it will become the sole content without surroundings.This frame > Show only this frame
(or Open frame in new tab/window) (Firefox)#
) from URLTechnical restrictions
locaStorage
. The only mean to save some state across iframe reloads is to (ab)usewindow.name
.Notes
location.hash
assignment but it throws onhistory.pushState
;location.hash
assignment (as it was top level navigation) but allowshistory.pushState
. If my memory serves, old versions of Chrome treated hash as content continuation and wrote it into document, sodata:text/html,content?search#hash
had contentcontent?search#hash
andlocation.hash
empty, now both browsers agree that content iscontent?search
and location.hash is#hash
. DataURI docs say nothing about#hash
part.Online variation of this, served over HTTP: https://myfonj.github.io/sandbox.html