Last active
September 20, 2015 22:14
-
-
Save psema4/d2e1d1d504e8786b7238 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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