35 lines
730 B
JavaScript
35 lines
730 B
JavaScript
|
class Config {
|
||
|
constructor() {
|
||
|
this.config = {};
|
||
|
this.name = ''
|
||
|
}
|
||
|
|
||
|
loadConfigByName(name) {
|
||
|
this.saveConfig();
|
||
|
this.name = 'config-' + name;
|
||
|
this.config = JSON.parse(this.name);
|
||
|
}
|
||
|
|
||
|
saveConfig() {
|
||
|
if (this.name !== '') {
|
||
|
localStorage.setItem(this.name, JSON.stringify(this.config));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
addItem(name, value) {
|
||
|
this.config[name] = value;
|
||
|
}
|
||
|
|
||
|
removeItem(name) {
|
||
|
delete this.config[name];
|
||
|
}
|
||
|
|
||
|
getItem(name, def) {
|
||
|
let value = this.config[name];
|
||
|
if (value === undefined || value === null) {
|
||
|
this.config[name] = def;
|
||
|
value = def;
|
||
|
}
|
||
|
return value;
|
||
|
}
|
||
|
}
|