Skip to content

Instantly share code, notes, and snippets.

@bblanchon
Created November 6, 2017 09:27
Show Gist options
  • Save bblanchon/6244d75d53f0ee1f4037745d59a42298 to your computer and use it in GitHub Desktop.
Save bblanchon/6244d75d53f0ee1f4037745d59a42298 to your computer and use it in GitHub Desktop.
Leanpub: recover lost manuscript from browser cache
// Leanpub: recovering lost manuscript
// -----------------------------------
//
// I lost the whole content of my Leanpub book after switching to GitHub.
// Fortunately, the manuscript files were still on my browser local storage.
// I was able to recover the complete manuscript using the following script.
//
// If this happens to you too, follow these steps:
//
// 1. Open your browser to https://leanpub.com
// 2. Open a developer console
// 3. Copy this script
// 4. Paste it in the developer console
// 5. Press enter to trigger the execution of the script
// 6. The browser will complain that a lot of files are being download,
// just click on "Allow".
//
// Admittedly, 6 steps sounds like a lot, but it takes no more than 15 seconds.
function download(data, filename, type) {
var file = new Blob([data], {type: type});
var a = document.createElement("a");
var url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
for( var key in localStorage ) {
var obj = JSON.parse(localStorage[key]);
if( obj && obj.filename && obj.content ) {
download(obj.content, obj.filename, 'text/markdown');
}
}
@bblanchon
Copy link
Author

See the script in action: https://youtu.be/4VysLo1zvh4

@bblanchon
Copy link
Author

Whoops! I just discover that Leanpub stores a history in the "Versions" tab 😀
A version is saved just before the switch to GitHub, so it's easy to recover from that.

I'm keeping this script online as it may serve as an alternative solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment