Merge pull request #1110 from ggodpl/main

add listeners to betterSettings.js
This commit is contained in:
slweeb 2025-05-16 22:22:43 -04:00 committed by GitHub
commit f4f70fbdfb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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";