Skip to content

Instantly share code, notes, and snippets.

@psema4
Last active September 20, 2015 22:14
Show Gist options
  • Save psema4/d2e1d1d504e8786b7238 to your computer and use it in GitHub Desktop.
Save psema4/d2e1d1d504e8786b7238 to your computer and use it in GitHub Desktop.
// store application state and/or data in an applications' location hash
//
// inspired by: urlHosted http://urlhosted.graphicore.de/about.html
// depends on: jszip https://github.com/Stuk/jszip
window.addEventListener('load', function() {
console.log('starting up...');
var zip = new JSZip();
if (window.location.hash === '') {
console.log('snapshot not found, generating base image...');
zip.file('etc/license', 'http://unlicense.org/');
zip.file('etc/motd', "Hello World\n\nWelcome to url-persistence\n");
window.location.hash = zip.generate({ type: 'base64' });
console.log('refresh the page to restore the current snapshot');
} else {
console.log('restoring snapshot...');
zip.load(window.location.hash.replace(/^#/, ''), { base64: true });
// cat /etc/motd
console.log(zip.file('etc/motd').asText());
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment