use proxy to make code more reliable

This commit is contained in:
MathMan05 2025-01-20 18:07:52 -06:00
parent 7cf606d705
commit e2422ffc9e
4 changed files with 25 additions and 13 deletions

View file

@ -569,12 +569,10 @@ class Channel extends SnowFlake {
if (childrendiv.style.height !== "0px") { if (childrendiv.style.height !== "0px") {
decoration.classList.add("hiddencat"); decoration.classList.add("hiddencat");
this.perminfo.collapsed = true; this.perminfo.collapsed = true;
this.localuser.userinfo.updateLocal();
childrendiv.style.height = "0px"; childrendiv.style.height = "0px";
} else { } else {
decoration.classList.remove("hiddencat"); decoration.classList.remove("hiddencat");
this.perminfo.collapsed = false; this.perminfo.collapsed = false;
this.localuser.userinfo.updateLocal();
childrendiv.style.height = childrendiv.scrollHeight + "px"; childrendiv.style.height = childrendiv.scrollHeight + "px";
} }
}; };
@ -907,7 +905,6 @@ class Channel extends SnowFlake {
const buttons = options.addOptions("", {ltr: true}); const buttons = options.addOptions("", {ltr: true});
buttons.addButtonInput("", "Yes", () => { buttons.addButtonInput("", "Yes", () => {
this.perminfo.nsfwOk = true; this.perminfo.nsfwOk = true;
this.localuser.userinfo.updateLocal();
this.getHTML(); this.getHTML();
}); });
buttons.addButtonInput("", "No", () => { buttons.addButtonInput("", "No", () => {
@ -946,7 +943,6 @@ class Channel extends SnowFlake {
} }
this.guild.prevchannel = this; this.guild.prevchannel = this;
this.guild.perminfo.prevchannel = this.id; this.guild.perminfo.prevchannel = this.id;
this.localuser.userinfo.updateLocal();
this.localuser.channelfocus = this; this.localuser.channelfocus = this;
if ( if (

View file

@ -12,6 +12,9 @@ class Hover {
elm.addEventListener("mouseover", () => { elm.addEventListener("mouseover", () => {
timeOut = setTimeout(async () => { timeOut = setTimeout(async () => {
elm2 = await this.makeHover(elm); elm2 = await this.makeHover(elm);
elm2.addEventListener("mouseover", () => {
elm2.remove();
});
}, 300); }, 300);
}); });
elm.addEventListener("mouseout", () => { elm.addEventListener("mouseout", () => {

View file

@ -156,7 +156,6 @@ class Localuser {
} }
this.pingEndpoint(); this.pingEndpoint();
this.userinfo.updateLocal();
} }
inrelation = new Set<User>(); inrelation = new Set<User>();
outoffocus(): void { outoffocus(): void {
@ -358,7 +357,6 @@ class Localuser {
this.info = newurls; this.info = newurls;
this.serverurls = newurls; this.serverurls = newurls;
this.userinfo.json.serverurls = this.info; this.userinfo.json.serverurls = this.info;
this.userinfo.updateLocal();
break; break;
} }
break; break;
@ -369,7 +367,6 @@ class Localuser {
this.info = newurls; this.info = newurls;
this.serverurls = newurls; this.serverurls = newurls;
this.userinfo.json.serverurls = this.info; this.userinfo.json.serverurls = this.info;
this.userinfo.updateLocal();
break; break;
} }
break; break;
@ -382,7 +379,6 @@ class Localuser {
this.info = newurls; this.info = newurls;
this.serverurls = newurls; this.serverurls = newurls;
this.userinfo.json.serverurls = this.info; this.userinfo.json.serverurls = this.info;
this.userinfo.updateLocal();
} }
break; break;
} }
@ -1764,7 +1760,6 @@ class Localuser {
this.botTokens.set(appId, updateJSON.token); this.botTokens.set(appId, updateJSON.token);
if (this.perminfo.applications[appId]) { if (this.perminfo.applications[appId]) {
this.perminfo.applications[appId] = updateJSON.token; this.perminfo.applications[appId] = updateJSON.token;
this.userinfo.updateLocal();
} }
}); });
const text = form.addText( const text = form.addText(
@ -1776,7 +1771,6 @@ class Localuser {
const check = form.addOptions("", {noSubmit: true}); const check = form.addOptions("", {noSubmit: true});
if (!this.perminfo.applications) { if (!this.perminfo.applications) {
this.perminfo.applications = {}; this.perminfo.applications = {};
this.userinfo.updateLocal();
} }
const checkbox = check.addCheckboxInput(I18n.getTranslation("localuser.saveToken"), () => {}, { const checkbox = check.addCheckboxInput(I18n.getTranslation("localuser.saveToken"), () => {}, {
initState: !!this.perminfo.applications[appId], initState: !!this.perminfo.applications[appId],
@ -1785,14 +1779,12 @@ class Localuser {
if (_) { if (_) {
if (this.botTokens.has(appId)) { if (this.botTokens.has(appId)) {
this.perminfo.applications[appId] = this.botTokens.get(appId); this.perminfo.applications[appId] = this.botTokens.get(appId);
this.userinfo.updateLocal();
} else { } else {
alert(I18n.getTranslation("localuser.noToken")); alert(I18n.getTranslation("localuser.noToken"));
checkbox.setState(false); checkbox.setState(false);
} }
} else { } else {
delete this.perminfo.applications[appId]; delete this.perminfo.applications[appId];
this.userinfo.updateLocal();
} }
}); });
form.addButtonInput("", I18n.getTranslation("localuser.advancedBot"), () => { form.addButtonInput("", I18n.getTranslation("localuser.advancedBot"), () => {

View file

@ -107,8 +107,29 @@ export class Specialuser {
this.json.localuserStore = e; this.json.localuserStore = e;
this.updateLocal(); this.updateLocal();
} }
proxySave(e: Object) {
return new Proxy(e, {
set: (target, p, newValue, receiver) => {
const bool = Reflect.set(target, p, newValue, receiver);
this.updateLocal();
return bool;
},
get: (target, p, receiver) => {
const value = Reflect.get(target, p, receiver) as unknown;
if (value instanceof Object) {
return this.proxySave(value);
}
return value;
},
});
}
get localuserStore() { get localuserStore() {
return this.json.localuserStore; type jsonParse = {
[key: string | number]: any;
};
return this.proxySave(this.json.localuserStore) as {
[key: string | number]: jsonParse;
};
} }
set id(e) { set id(e) {
this.json.id = e; this.json.id = e;