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:
25
SB.js
25
SB.js
@@ -1,19 +1,36 @@
|
|||||||
SB = {};
|
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() {
|
function configProxy() {
|
||||||
chrome.storage.onChanged.addListener((changes, namespace) => {
|
chrome.storage.onChanged.addListener((changes, namespace) => {
|
||||||
for (key in changes) {
|
for (key in changes) {
|
||||||
Reflect.set(SB.localconfig, key, changes[key].newValue);
|
Reflect.set(SB.localconfig, key, changes[key].newValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var handler = {
|
var handler = {
|
||||||
set: function(obj, prop, value) {
|
set: function(obj, prop, value) {
|
||||||
chrome.storage.sync.set({
|
chrome.storage.sync.set({
|
||||||
[prop]: value
|
[prop]: storeEncode(value)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
get: function(obj, prop) {
|
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();
|
addDefaults();
|
||||||
SB.config = configProxy();
|
SB.config = configProxy();
|
||||||
migrate();
|
migrate();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SB.defaults = {
|
SB.defaults = {
|
||||||
|
|||||||
Reference in New Issue
Block a user