mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 05:27:03 +03:00
Made decodeStoredItem detect item type
Not tested because SB.config cant be used anymore :(
This commit is contained in:
@@ -128,7 +128,7 @@ var Config: SBObject = {
|
|||||||
function encodeStoredItem(data) {
|
function encodeStoredItem(data) {
|
||||||
// if data is SBMap convert to json for storing
|
// if data is SBMap convert to json for storing
|
||||||
if(!(data instanceof SBMap)) return data;
|
if(!(data instanceof SBMap)) return data;
|
||||||
return JSON.stringify(data);
|
return Array.from(data.entries());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,18 +138,19 @@ function encodeStoredItem(data) {
|
|||||||
* @param {*} data
|
* @param {*} data
|
||||||
*/
|
*/
|
||||||
function decodeStoredItem(id: string, data) {
|
function decodeStoredItem(id: string, data) {
|
||||||
if(typeof data !== "string") return data;
|
if(!Config.localConfig[id]) return data;
|
||||||
|
|
||||||
try {
|
|
||||||
let str = JSON.parse(data);
|
|
||||||
|
|
||||||
if(!Array.isArray(str)) return data;
|
|
||||||
return new SBMap(id, str);
|
|
||||||
} catch(e) {
|
|
||||||
|
|
||||||
// If all else fails, return the data
|
if(Config.localConfig[id] instanceof SBMap) {
|
||||||
return data;
|
try {
|
||||||
|
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 {
|
function configProxy(): any {
|
||||||
@@ -240,4 +241,4 @@ function addDefaults() {
|
|||||||
// Sync config
|
// Sync config
|
||||||
setupConfig();
|
setupConfig();
|
||||||
|
|
||||||
export default Config;
|
export default Config;
|
||||||
|
|||||||
Reference in New Issue
Block a user