Skip to content

Instantly share code, notes, and snippets.

@MohamedElashri
Created March 23, 2024 01:26
Show Gist options
  • Save MohamedElashri/50395fadc7b3fb143c05a8cff2de81b6 to your computer and use it in GitHub Desktop.
Save MohamedElashri/50395fadc7b3fb143c05a8cff2de81b6 to your computer and use it in GitHub Desktop.
Plain text editor as bookmarklet (have new, load, save text features)
data: text / html;
charset = utf - 8, < !doctype html > < title > texed < /title><style>a,input{display:none}button,label{position:absolute;right:0;transform:translateY(-50%);box-sizing:border-box;width:3em;border-color:%23777;color:%23ddd;background:%23555;text-align:center;font:10pt sans-serif;cursor:pointer}input:checked+label{color:%237f7}</style > < body style = margin: 0;
background: % 23333 onload = t.focus() > < input id = f type = file > < a id = a download = text.txt > < /a><label id=g title="Text length in characters" style=top:10vh;width:3.75em;background:transparent;word-wrap:break-word;font-size:8pt;cursor:auto>0</label > < input id = w type = checkbox checked onchange = t.style.whiteSpace = w.checked && 'pre-wrap' || 'pre' > < label
for = w title = "Toggle word-wrap"
style = "top:25vh;padding:.2em 0" > Wrap < /label><button title="New text" style=top:40vh onclick="(!t.value||confirm('Clear existing text?'))&&(t.value='');l.dc=false;l.textContent='LF';t.focus()">New</button > < button title = "Load text from file"
style = top: 55 vh onclick = "(e=f.cloneNode()).onchange=async function(x){x=await e.files[0].text();b=x.replace(/\r\n/g,'\n');l.textContent=(l.dc=b!==x)&&'CRLF'||'LF';t.value=b};e.click();t.focus()" > Load < /button><button title="Save text into file" style=top:70vh onclick="a.href=window.URL.createObjectURL(new Blob([l.dc?t.value.replace(/\n/g,'\r\n'):t.value],{type:'text/plain
'}));a.click();t.focus()">Save</button><label id=l title="New line type" style=top:85vh;background:transparent;color:%237dd onclick=l.textContent=(l.dc=!l.dc)&&'
CRLF '||'
LF '>LF</label><textarea id=t spellcheck=false tabindex=0 style="margin:0;outline:0!important;border:0;box-sizing:border-box;width:calc(100vw - 2.5em);height:calc(100vh - 1px);resize:none;padding:.5em;font-family:monospace;font-size:large;background:%23444;color:%23ffd" oninput="g.textContent=t.value.length;onbeforeunload=t.value&&function(e){e.returnValue='
You have unsaved text.
'}||null">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment