SponsorBlock/SB.js

61 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-12-31 21:07:43 +01:00
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() {
await fetchConfig();
2019-12-31 23:46:16 +01:00
addDefaults();
2019-12-31 21:07:43 +01:00
SB.config = configProxy();
}
2019-12-31 23:46:16 +01:00
SB.defaults = {
"startSponsorKeybind": ";",
"submitKeybind": "'",
"minutesSaved": 0,
2019-12-31 23:48:29 +01:00
"skipCount": 0,
"disableSkipping": false,
2019-12-31 23:54:02 +01:00
"disableAutoSkip": false,
"trackViewCount": false
2019-12-31 23:46:16 +01:00
}
// Reset config
function resetConfig() {
SB.config = SB.defaults;
};
// Add defaults
function addDefaults() {
Object.keys(SB.defaults).forEach(key => {
if(!SB.localconfig.hasOwnProperty(key)) {
2020-01-01 13:27:59 +01:00
SB.localconfig[key] = SB.defaults[key];
2019-12-31 23:46:16 +01:00
}
});
};
2019-12-31 21:07:43 +01:00
// Sync config
config();