add listeners to betterSettings.js

This commit is contained in:
ggodpl 2025-05-17 02:10:40 +02:00
parent e81df2f182
commit 5c4e2bb134
1 changed files with 8 additions and 0 deletions

View File

@ -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";