Skip to content

Instantly share code, notes, and snippets.

@fliptopbox
Created January 22, 2019 19:52
Show Gist options
  • Save fliptopbox/a2250dfcb876897b42d1c23e64230524 to your computer and use it in GitHub Desktop.
Save fliptopbox/a2250dfcb876897b42d1c23e64230524 to your computer and use it in GitHub Desktop.
/*
a bookmarklet that dumps localStorage
and saves the stringified JSON
to your downloads folder.
1. createa new bookmark (page)
2. in the address field type:
javascript: .... (paste below code)
3. Click the new button
*/
(function () {
let filename = window.prompt("Filename");
const id = "localStorage";
const data = window.localStorage;
filename = `${filename}-${id}`;
const text = JSON.stringify(data);
const element = document.createElement("a");
const payload = encodeURIComponent(text);
element.setAttribute("href", "data:text/json;charset=utf-8," + payload);
element.setAttribute("download", `${filename}.json`);
element.style.display = "none";
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment