mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-29 09:43:16 +00:00
Add localstorage.js
This commit is contained in:
parent
5f40f39435
commit
1a423ce139
1 changed files with 33 additions and 0 deletions
33
resources/assets/js/components/localstorage.js
vendored
Normal file
33
resources/assets/js/components/localstorage.js
vendored
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
window.ls = {};
|
||||||
|
|
||||||
|
window.ls.get = function(key) {
|
||||||
|
return JSON.parse(localStorage.getItem(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
window.ls.set = function(key, val) {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(key, JSON.stringify(val));
|
||||||
|
return true;
|
||||||
|
} catch(e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.ls.del = function(key) {
|
||||||
|
try {
|
||||||
|
localStorage.removeItem(key);
|
||||||
|
return true;
|
||||||
|
} catch(e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.ls.clear = function() {
|
||||||
|
try {
|
||||||
|
localStorage.clear();
|
||||||
|
return true;
|
||||||
|
} catch(e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue