mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
Update utils.js
This commit is contained in:
parent
3fbb689e0a
commit
272698f97b
1 changed files with 34 additions and 0 deletions
34
utils.js
34
utils.js
|
@ -1,3 +1,37 @@
|
|||
SB = {};
|
||||
|
||||
function configProxy() {
|
||||
chrome.storage.onChanged.addListener((changes, namespace) => {
|
||||
for (key in changes) {
|
||||
localconfig[key] = changes[key].newValue;
|
||||
}
|
||||
});
|
||||
var handler = {
|
||||
set: function(obj, prop, value) {
|
||||
chrome.storage.sync.set({
|
||||
[prop]: value
|
||||
})
|
||||
},
|
||||
get: function(obj, prop) {
|
||||
return localconfig[prop]
|
||||
}
|
||||
};
|
||||
return new Proxy({}, handler);
|
||||
}
|
||||
|
||||
fetchConfig = _ => new Promise(function(resolve, reject) {
|
||||
chrome.storage.sync.get(null, function(items) {
|
||||
localconfig = items; // Data is ready
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
async function config() {
|
||||
localconfig = {};
|
||||
await fetchConfig();
|
||||
SB.config = configProxy();
|
||||
}
|
||||
|
||||
// Function that can be used to wait for a condition before returning
|
||||
async function wait(condition, timeout = 5000, check = 100) {
|
||||
return await new Promise((resolve, reject) => {
|
||||
|
|
Loading…
Reference in a new issue