mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-09-20 04:53:43 +02:00
Comments
This commit is contained in:
parent
4cdb874b4f
commit
f7a3f98ad3
1 changed files with 8 additions and 2 deletions
10
SB.js
10
SB.js
|
@ -9,16 +9,21 @@ SB = {
|
||||||
|
|
||||||
// Function setup
|
// Function setup
|
||||||
|
|
||||||
|
// Allows a map to be conveted into json form
|
||||||
|
// Currently used for local storage
|
||||||
Map.prototype.toJSON = function() {
|
Map.prototype.toJSON = function() {
|
||||||
return Array.from(this.entries());
|
return Array.from(this.entries());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Proxy Map changes to Map in SB.localConfig
|
||||||
|
// Saves the changes to chrome.storage in json form
|
||||||
class MapIO {
|
class MapIO {
|
||||||
constructor(id) {
|
constructor(id) {
|
||||||
|
// The name of the item in the array
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
// A local copy of the map (SB.config.mapname.map)
|
||||||
this.map = SB.localConfig[this.id];
|
this.map = SB.localConfig[this.id];
|
||||||
}
|
}
|
||||||
|
|
||||||
set(key, value) {
|
set(key, value) {
|
||||||
// Proxy to map
|
// Proxy to map
|
||||||
this.map.set(key, value);
|
this.map.set(key, value);
|
||||||
|
@ -65,6 +70,7 @@ class MapIO {
|
||||||
* @param {*} data
|
* @param {*} data
|
||||||
*/
|
*/
|
||||||
function encodeStoredItem(data) {
|
function encodeStoredItem(data) {
|
||||||
|
// if data is Map convert to json for storing
|
||||||
if(!(data instanceof Map)) return data;
|
if(!(data instanceof Map)) return data;
|
||||||
return JSON.stringify(data);
|
return JSON.stringify(data);
|
||||||
}
|
}
|
||||||
|
@ -120,7 +126,7 @@ function configProxy() {
|
||||||
deleteProperty(obj, prop) {
|
deleteProperty(obj, prop) {
|
||||||
chrome.storage.sync.remove(prop);
|
chrome.storage.sync.remove(prop);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return new Proxy({handler}, handler);
|
return new Proxy({handler}, handler);
|
||||||
|
|
Loading…
Reference in a new issue