6 ms·
Been doing something similar with save files for my game. Line 1 is "<!DOCTYPE html><html><head><script>const rawData =" and line 2 is all the state. Then the
by mcteamster 1y ago
Been doing something similar with save files for my game. Line 1 is "<!DOCTYPE html><html><head><script>const rawData =" and line 2 is all the state.
Then the save button downloads document.documentElement.outerHTML with line 2 replaced by the current state. No server required.
https://github.com/mcteamster/white/blob/main/src/lib/data.ts#L56 https://github.com/mcteamster/white/blob/main/src/lib/data.t...
- fallinditch 1y agoI am trying something similar: I made game as a standalone HTML file with a feature that allows users to edit text and save as a new local version. Works on my phone (Android with Brave) but not on iOS with Safari.
- qingcharles 1y agoI keep this bookmark in Chrome which lets me open an editor in a tab and Chrome maintains the state of the textarea even through reboots as long as you don't close the tab: data:text/html,<html><head><title>Notepad</title><style>html,body{margin:0;padding:0;}textarea{padding:10px;font-family:Courier;font-size:16px;height:100%;width:100%;border:none;outline:none;}</style></head><body><textarea style="height:100%;width:100%;font-size:16px;padding:10px;"></textarea><script>document.getElementsByTagName('textarea')[0].focus()</script></body></html>
- b2ccb2 1y agoYou can get rid of the JS by setting the autofocus[1] attribute to the textarea. [1] https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/autofocus https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/...
- qingcharles 1y agoThank you, I'm going to try this.
- qingcharles 1y agoThanks, I trimmed it down to this: data:text/html,<title>Notepad</title><textarea autofocus spellcheck=0 style="position:fixed;inset:0;padding:1em;border:0;font:monospace">