mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-07 20:17:05 +03:00
Moving to separate due to load order
This commit is contained in:
37
utils.js
37
utils.js
@@ -1,40 +1,3 @@
|
|||||||
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();
|
|
||||||
|
|
||||||
// Function that can be used to wait for a condition before returning
|
// Function that can be used to wait for a condition before returning
|
||||||
async function wait(condition, timeout = 5000, check = 100) {
|
async function wait(condition, timeout = 5000, check = 100) {
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user