compatible for LZString.decompress
This commit is contained in:
parent
d837ab1120
commit
bb6241dedf
@ -163,28 +163,30 @@ utils.prototype.setLocalStorage = function(key, value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utils.prototype.decompress = function (value) {
|
||||||
|
try {
|
||||||
|
var output = lzw_decode(value);
|
||||||
|
if (core.isset(output) && output.length > 0)
|
||||||
|
return JSON.parse(output);
|
||||||
|
}
|
||||||
|
catch (e) {}
|
||||||
|
try {
|
||||||
|
var output = LZString.decompress(value);
|
||||||
|
if (core.isset(output) && output.length > 0)
|
||||||
|
return JSON.parse(output);
|
||||||
|
}
|
||||||
|
catch (e) {}
|
||||||
|
try {
|
||||||
|
return JSON.parse(value);
|
||||||
|
}
|
||||||
|
catch (e) {main.log(e);}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
////// 获得本地存储 //////
|
////// 获得本地存储 //////
|
||||||
utils.prototype.getLocalStorage = function(key, defaultValue) {
|
utils.prototype.getLocalStorage = function(key, defaultValue) {
|
||||||
try {
|
var res = this.decompress(localStorage.getItem(core.firstData.name+"_"+key));
|
||||||
var value = localStorage.getItem(core.firstData.name+"_"+key);
|
return res==null?defaultValue:res;
|
||||||
if (core.isset(value)) {
|
|
||||||
var output = lzw_decode(value);
|
|
||||||
if (core.isset(output) && output.length>0) {
|
|
||||||
try {
|
|
||||||
return JSON.parse(output);
|
|
||||||
}
|
|
||||||
catch (ee) {
|
|
||||||
// Ignore, use default value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return JSON.parse(value);
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
main.log(e);
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////// 移除本地存储 //////
|
////// 移除本地存储 //////
|
||||||
@ -244,18 +246,9 @@ utils.prototype.getLocalForage = function (key, defaultValue, successCallback, e
|
|||||||
else {
|
else {
|
||||||
if (!core.isset(successCallback)) return;
|
if (!core.isset(successCallback)) return;
|
||||||
if (core.isset(value)) {
|
if (core.isset(value)) {
|
||||||
try {
|
var res = core.utils.decompress(value);
|
||||||
var output = lzw_decode(value);
|
successCallback(res==null?defaultValue:res);
|
||||||
if (core.isset(output) && output.length>0) {
|
return;
|
||||||
try {
|
|
||||||
successCallback(JSON.parse(output));
|
|
||||||
return;
|
|
||||||
} catch (ee) {main.log(ee);}
|
|
||||||
}
|
|
||||||
successCallback(JSON.parse(value));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
catch (e) {main.log(e);}
|
|
||||||
}
|
}
|
||||||
successCallback(defaultValue);
|
successCallback(defaultValue);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user