SponsorBlock/SB.js

68 lines
1.4 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();
2020-01-01 15:45:34 +01:00
addDefaults();
2019-12-31 21:07:43 +01:00
SB.config = configProxy();
}
2019-12-31 23:46:16 +01:00
SB.defaults = {
2020-01-01 19:00:47 +01:00
"sponsorTimeKey": [];
2019-12-31 23:46:16 +01:00
"startSponsorKeybind": ";",
"submitKeybind": "'",
"minutesSaved": 0,
2019-12-31 23:48:29 +01:00
"skipCount": 0,
2020-01-01 15:45:22 +01:00
"sponsorTimesContributed": 0,
2019-12-31 23:48:29 +01:00
"disableSkipping": false,
2019-12-31 23:54:02 +01:00
"disableAutoSkip": false,
2020-01-01 13:35:54 +01:00
"trackViewCount": false,
2020-01-01 15:04:49 +01:00
"dontShowNotice": false,
"hideVideoPlayerControls": false,
"hideInfoButtonPlayerControls": false,
"hideDeleteButtonPlayerControls": false,
"dontShowNoticeOld": 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();