class Settings { constructor() { this.active = {}; this.default = ExtensionConf; } async init() { const settings = await this.get('uw-settings'); if(Debug.debug) { console.log("[Settings::init] Configuration fetched from background script:", settings); } // if there's no settings saved, return default settings. if(! settings || (Object.keys(newSettings).length === 0 && newSettings.constructor === Object)) { this.setDefaultSettings(); this.active = this.getDefaultSettings(); return this.active; } // if there's settings, set saved object as active settings this.active = settings; // check if extension has been updated. If not, return settings as they were retreived const uwVersion = runtime.getManifest().version; if(settings.version === uwVersion) { if(Debug.debug) { console.log("[Settings::init] extension was saved with current version of ultrawidify (", uwVersion, "). Returning object as-is."); } return this.active; } // if extension has been updated, update existing settings with any options added in the // new version. In addition to that, we remove old keys that are no longer used. this.active = ObjectCopy.addNew(settings, this.default); this.set(this.active); return this.active; } async get() { if (BrowserDetect.firefox || BrowserDetect.edge) { return browser.storage.sync.get('uw-settings'); } else if (BrowserDetect.chrome) { return chrome.storage.sync.get('uw-settings'); } } async set(extensionConf) { if (BrowserDetect.firefox || BrowserDetect.edge) { return browser.storage.sync.set('uw-settings', extensionConf); } else if (BrowserDetect.chrome) { return chrome.storage.sync.set('uw-settings', extensionConf); } } getDefaultSettings() { return JSON.parse(JSON.stringify(this.default)); } setDefaultSettings() { this.set(this.default); } // ----------------------------------------- // Nastavitve za posamezno stran // Config for a given page: // // : { // status: