mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-14 07:27:05 +03:00
Map storage encoding
This commit is contained in:
23
SB.js
23
SB.js
@@ -1,5 +1,22 @@
|
||||
SB = {};
|
||||
|
||||
Map.prototype.toJSON = function() {
|
||||
return Array.from(this.entries());
|
||||
};
|
||||
|
||||
function storeEncode(data) {
|
||||
if(!(data instanceof Map)) return data;
|
||||
return JSON.stringify(data);
|
||||
}
|
||||
|
||||
function strParser(data) {
|
||||
try {
|
||||
return new Map(JSON.parse(data));
|
||||
} catch(e) {
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
function configProxy() {
|
||||
chrome.storage.onChanged.addListener((changes, namespace) => {
|
||||
for (key in changes) {
|
||||
@@ -9,11 +26,11 @@ function configProxy() {
|
||||
var handler = {
|
||||
set: function(obj, prop, value) {
|
||||
chrome.storage.sync.set({
|
||||
[prop]: value
|
||||
[prop]: storeEncode(value)
|
||||
});
|
||||
},
|
||||
get: function(obj, prop) {
|
||||
return Reflect.get(SB.localconfig, prop);
|
||||
return strParser(Reflect.get(SB.localconfig, prop));
|
||||
}
|
||||
|
||||
};
|
||||
@@ -42,8 +59,6 @@ async function config() {
|
||||
addDefaults();
|
||||
SB.config = configProxy();
|
||||
migrate();
|
||||
|
||||
|
||||
}
|
||||
|
||||
SB.defaults = {
|
||||
|
||||
Reference in New Issue
Block a user