Made decodeStoredItem detect item type

Not tested because SB.config cant be used anymore :(
This commit is contained in:
Official Noob
2020-02-04 22:16:40 +00:00
committed by GitHub
parent feda7fd1a0
commit 8896c5707a

View File

@@ -128,7 +128,7 @@ var Config: SBObject = {
function encodeStoredItem(data) {
// if data is SBMap convert to json for storing
if(!(data instanceof SBMap)) return data;
return JSON.stringify(data);
return Array.from(data.entries());
}
/**
@@ -138,19 +138,20 @@ function encodeStoredItem(data) {
* @param {*} data
*/
function decodeStoredItem(id: string, data) {
if(typeof data !== "string") return data;
if(!Config.localConfig[id]) return data;
if(Config.localConfig[id] instanceof SBMap) {
try {
let str = JSON.parse(data);
if(!Array.isArray(str)) return data;
return new SBMap(id, str);
if(!Array.isArray(data)) return data;
return new SBMap(id, data);
} catch(e) {
console.error("Failed to parse SBMap: "+ id);
}
}
// If all else fails, return the data
return data;
}
}
function configProxy(): any {
chrome.storage.onChanged.addListener((changes, namespace) => {