diff options
| author | Haishan <[email protected]> | 2019-04-20 15:47:43 +0800 |
|---|---|---|
| committer | Haishan <[email protected]> | 2019-04-20 16:42:56 +0800 |
| commit | eda2501b1d68c6f82a4a824ffe12caf5be7b33f2 (patch) | |
| tree | 25ada6388737a698c66380fe5bab22d5e4c4bf69 /src/misc | |
| parent | e68f4ce9664f8164fd6aab284feb9ebed9f2ecdb (diff) | |
feat(config): add button to clear local storage
Diffstat (limited to 'src/misc')
| -rw-r--r-- | src/misc/storage.js | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/misc/storage.js b/src/misc/storage.js index ce22038..7424ae1 100644 --- a/src/misc/storage.js +++ b/src/misc/storage.js @@ -1,8 +1,10 @@ // manage localStorage -function loadState(key) { +const StorageKey = 'yacd.haishan.me'; + +function loadState() { try { - const serialized = localStorage.getItem(key); + const serialized = localStorage.getItem(StorageKey); if (!serialized) return undefined; return JSON.parse(serialized); } catch (err) { @@ -10,18 +12,18 @@ function loadState(key) { } } -function saveState(key, state) { +function saveState(state) { try { const serialized = JSON.stringify(state); - localStorage.setItem(key, serialized); + localStorage.setItem(StorageKey, serialized); } catch (err) { // ignore } } -function clearState(key) { +function clearState() { try { - localStorage.removeItem(key); + localStorage.removeItem(StorageKey); } catch (err) { // ignore } |
