class Settings { constructor(activeSettings) { this.active = activeSettings ? activeSettings : {}; 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(settings).length === 0 && settings.constructor === Object)) { console.log("NO SETTINGS") 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 var uwVersion; if (BrowserDetect.firefox) { uwVersion = browser.runtime.getManifest().version; } else if (BrowserDetect.chrome) { uwVersion = chrome.runtime.getManifest().version; } else if (BrowserDetect.edge) { uwVersion = browser.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) { const ret = browser.storage.sync.get('uw-settings'); return ret['uw-settings']; } else if (BrowserDetect.chrome) { const ret = chrome.storage.sync.get('uw-settings'); return ret['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}); } } async setActive(activeSettings) { this.active = activeSettings; } async setProp(prop, value) { this.active[prop] = value; } async save() { this.set(this.active); } getDefaultSettings() { return JSON.parse(JSON.stringify(this.default)); } setDefaultSettings() { this.set(this.default); } // ----------------------------------------- // Nastavitve za posamezno stran // Config for a given page: // // : { // status: