mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 19:47:04 +03:00
File used to control the SB object
This commit is contained in:
36
SB.js
Normal file
36
SB.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
SB = {};
|
||||||
|
|
||||||
|
function configProxy() {
|
||||||
|
chrome.storage.onChanged.addListener((changes, namespace) => {
|
||||||
|
for (key in changes) {
|
||||||
|
SB.localconfig[key] = changes[key].newValue;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var handler = {
|
||||||
|
set: function(obj, prop, value) {
|
||||||
|
chrome.storage.sync.set({
|
||||||
|
[prop]: value
|
||||||
|
})
|
||||||
|
},
|
||||||
|
get: function(obj, prop) {
|
||||||
|
return SB.localconfig[prop]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return new Proxy({}, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchConfig = _ => new Promise(function(resolve, reject) {
|
||||||
|
chrome.storage.sync.get(null, function(items) {
|
||||||
|
SB.localconfig = items; // Data is ready
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
async function config() {
|
||||||
|
SB.localconfig = {};
|
||||||
|
await fetchConfig();
|
||||||
|
SB.config = configProxy();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sync config
|
||||||
|
config();
|
||||||
Reference in New Issue
Block a user