mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 20:47:11 +03:00
Fixed sponsorTimes data on export and import
This commit is contained in:
@@ -33,6 +33,10 @@ interface SBObject {
|
|||||||
defaults: SBConfig;
|
defaults: SBConfig;
|
||||||
localConfig: SBConfig;
|
localConfig: SBConfig;
|
||||||
config: SBConfig;
|
config: SBConfig;
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
encodeStoredItem<T>(data: T): T | Array<any>;
|
||||||
|
convertJSON(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allows a SBMap to be conveted into json form
|
// Allows a SBMap to be conveted into json form
|
||||||
@@ -119,7 +123,11 @@ var Config: SBObject = {
|
|||||||
mobileUpdateShowCount: 0
|
mobileUpdateShowCount: 0
|
||||||
},
|
},
|
||||||
localConfig: null,
|
localConfig: null,
|
||||||
config: null
|
config: null,
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
encodeStoredItem,
|
||||||
|
convertJSON
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function setup
|
// Function setup
|
||||||
@@ -130,7 +138,7 @@ var Config: SBObject = {
|
|||||||
*
|
*
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
function encodeStoredItem(data) {
|
function encodeStoredItem<T>(data: T): T | Array<any> {
|
||||||
// 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 Array.from(data.entries());
|
return Array.from(data.entries());
|
||||||
@@ -142,7 +150,7 @@ function encodeStoredItem(data) {
|
|||||||
*
|
*
|
||||||
* @param {*} data
|
* @param {*} data
|
||||||
*/
|
*/
|
||||||
function decodeStoredItem(id: string, data) {
|
function decodeStoredItem<T>(id: string, data: T): T | SBMap<string, any> {
|
||||||
if (!Config.defaults[id]) return data;
|
if (!Config.defaults[id]) return data;
|
||||||
|
|
||||||
if (Config.defaults[id] instanceof SBMap) {
|
if (Config.defaults[id] instanceof SBMap) {
|
||||||
@@ -239,7 +247,7 @@ function resetConfig() {
|
|||||||
Config.config = Config.defaults;
|
Config.config = Config.defaults;
|
||||||
};
|
};
|
||||||
|
|
||||||
function convertJSON() {
|
function convertJSON(): void {
|
||||||
Object.keys(Config.localConfig).forEach(key => {
|
Object.keys(Config.localConfig).forEach(key => {
|
||||||
Config.localConfig[key] = decodeStoredItem(key, Config.localConfig[key]);
|
Config.localConfig[key] = decodeStoredItem(key, Config.localConfig[key]);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -379,7 +379,12 @@ function activatePrivateTextChange(element: HTMLElement) {
|
|||||||
// See if anything extra must be done
|
// See if anything extra must be done
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case "*":
|
case "*":
|
||||||
result = JSON.stringify(Config.localConfig);
|
let jsonData = JSON.parse(JSON.stringify(Config.localConfig));
|
||||||
|
|
||||||
|
// Fix sponsorTimes data as it is destroyed from the JSON stringify
|
||||||
|
jsonData.sponsorTimes = Config.encodeStoredItem(Config.localConfig.sponsorTimes);
|
||||||
|
|
||||||
|
result = JSON.stringify(jsonData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,7 +404,9 @@ function activatePrivateTextChange(element: HTMLElement) {
|
|||||||
for (const key in newConfig) {
|
for (const key in newConfig) {
|
||||||
Config.config[key] = newConfig[key];
|
Config.config[key] = newConfig[key];
|
||||||
}
|
}
|
||||||
|
Config.convertJSON();
|
||||||
|
|
||||||
|
// Reload options on page
|
||||||
init();
|
init();
|
||||||
|
|
||||||
if (newConfig.supportInvidious) {
|
if (newConfig.supportInvidious) {
|
||||||
@@ -457,6 +464,9 @@ function copyDebugOutputToClipboard() {
|
|||||||
},
|
},
|
||||||
config: JSON.parse(JSON.stringify(Config.localConfig)) // Deep clone config object
|
config: JSON.parse(JSON.stringify(Config.localConfig)) // Deep clone config object
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Fix sponsorTimes data as it is destroyed from the JSON stringify
|
||||||
|
output.config.sponsorTimes = Config.encodeStoredItem(Config.localConfig.sponsorTimes);
|
||||||
|
|
||||||
// Sanitise sensitive user config values
|
// Sanitise sensitive user config values
|
||||||
delete output.config.userID;
|
delete output.config.userID;
|
||||||
|
|||||||
Reference in New Issue
Block a user