Skip to content

Instantly share code, notes, and snippets.

@dzek69
Created March 18, 2021 11:34
Show Gist options
  • Save dzek69/6f02ca65e1a2ae2b798faa47fe71621d to your computer and use it in GitHub Desktop.
Save dzek69/6f02ca65e1a2ae2b798faa47fe71621d to your computer and use it in GitHub Desktop.
Save / restore all localStorage
const save = () => JSON.stringify(Object.keys(localStorage).reduce((acc, curr) => { acc[curr] = localStorage.getItem(curr); return acc; }, {}));
// Usage in console:
copy(save());
// new console
o = CTRL+V
restore(o);
const clean = () => { Object.keys(localStorage).forEach(k => localStorage.removeItem(k)); return true };
const restore = (o) => clean() && Object.entries(o).forEach(([key, val]) => localStorage.setItem(key, val));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment