add listeners to betterSettings.js
This commit is contained in:
parent
e81df2f182
commit
5c4e2bb134
|
|
@ -15,6 +15,7 @@ class Setting {
|
|||
this.defaultValue = defaultValue ?? type[1];
|
||||
this.description = description;
|
||||
this.validate = customValidator;
|
||||
this.listeners = [];
|
||||
}
|
||||
|
||||
set(value) {
|
||||
|
|
@ -23,6 +24,9 @@ class Setting {
|
|||
const settings = JSON.parse(localStorage.getItem(`${this.tabName}/settings`)) ?? {};
|
||||
settings[this.name] = value;
|
||||
localStorage.setItem(`${this.tabName}/settings`, JSON.stringify(settings));
|
||||
for (const listener of this.listeners) {
|
||||
listener(value);
|
||||
}
|
||||
}
|
||||
|
||||
update() {
|
||||
|
|
@ -42,6 +46,10 @@ class Setting {
|
|||
this.disabled = true;
|
||||
}
|
||||
|
||||
onUpdate(callback) {
|
||||
this.listeners.push(callback);
|
||||
}
|
||||
|
||||
#parseColor(colorString) {
|
||||
if (colorString instanceof Array) return parseColor(colorString[0]);
|
||||
if (typeof colorString != "string") return "#ffffff";
|
||||
|
|
|
|||
Loading…
Reference in New Issue