use proxy to make code more reliable
This commit is contained in:
parent
7cf606d705
commit
e2422ffc9e
4 changed files with 25 additions and 13 deletions
|
@ -569,12 +569,10 @@ class Channel extends SnowFlake {
|
|||
if (childrendiv.style.height !== "0px") {
|
||||
decoration.classList.add("hiddencat");
|
||||
this.perminfo.collapsed = true;
|
||||
this.localuser.userinfo.updateLocal();
|
||||
childrendiv.style.height = "0px";
|
||||
} else {
|
||||
decoration.classList.remove("hiddencat");
|
||||
this.perminfo.collapsed = false;
|
||||
this.localuser.userinfo.updateLocal();
|
||||
childrendiv.style.height = childrendiv.scrollHeight + "px";
|
||||
}
|
||||
};
|
||||
|
@ -907,7 +905,6 @@ class Channel extends SnowFlake {
|
|||
const buttons = options.addOptions("", {ltr: true});
|
||||
buttons.addButtonInput("", "Yes", () => {
|
||||
this.perminfo.nsfwOk = true;
|
||||
this.localuser.userinfo.updateLocal();
|
||||
this.getHTML();
|
||||
});
|
||||
buttons.addButtonInput("", "No", () => {
|
||||
|
@ -946,7 +943,6 @@ class Channel extends SnowFlake {
|
|||
}
|
||||
this.guild.prevchannel = this;
|
||||
this.guild.perminfo.prevchannel = this.id;
|
||||
this.localuser.userinfo.updateLocal();
|
||||
this.localuser.channelfocus = this;
|
||||
|
||||
if (
|
||||
|
|
|
@ -12,6 +12,9 @@ class Hover {
|
|||
elm.addEventListener("mouseover", () => {
|
||||
timeOut = setTimeout(async () => {
|
||||
elm2 = await this.makeHover(elm);
|
||||
elm2.addEventListener("mouseover", () => {
|
||||
elm2.remove();
|
||||
});
|
||||
}, 300);
|
||||
});
|
||||
elm.addEventListener("mouseout", () => {
|
||||
|
|
|
@ -156,7 +156,6 @@ class Localuser {
|
|||
}
|
||||
|
||||
this.pingEndpoint();
|
||||
this.userinfo.updateLocal();
|
||||
}
|
||||
inrelation = new Set<User>();
|
||||
outoffocus(): void {
|
||||
|
@ -358,7 +357,6 @@ class Localuser {
|
|||
this.info = newurls;
|
||||
this.serverurls = newurls;
|
||||
this.userinfo.json.serverurls = this.info;
|
||||
this.userinfo.updateLocal();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -369,7 +367,6 @@ class Localuser {
|
|||
this.info = newurls;
|
||||
this.serverurls = newurls;
|
||||
this.userinfo.json.serverurls = this.info;
|
||||
this.userinfo.updateLocal();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -382,7 +379,6 @@ class Localuser {
|
|||
this.info = newurls;
|
||||
this.serverurls = newurls;
|
||||
this.userinfo.json.serverurls = this.info;
|
||||
this.userinfo.updateLocal();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1764,7 +1760,6 @@ class Localuser {
|
|||
this.botTokens.set(appId, updateJSON.token);
|
||||
if (this.perminfo.applications[appId]) {
|
||||
this.perminfo.applications[appId] = updateJSON.token;
|
||||
this.userinfo.updateLocal();
|
||||
}
|
||||
});
|
||||
const text = form.addText(
|
||||
|
@ -1776,7 +1771,6 @@ class Localuser {
|
|||
const check = form.addOptions("", {noSubmit: true});
|
||||
if (!this.perminfo.applications) {
|
||||
this.perminfo.applications = {};
|
||||
this.userinfo.updateLocal();
|
||||
}
|
||||
const checkbox = check.addCheckboxInput(I18n.getTranslation("localuser.saveToken"), () => {}, {
|
||||
initState: !!this.perminfo.applications[appId],
|
||||
|
@ -1785,14 +1779,12 @@ class Localuser {
|
|||
if (_) {
|
||||
if (this.botTokens.has(appId)) {
|
||||
this.perminfo.applications[appId] = this.botTokens.get(appId);
|
||||
this.userinfo.updateLocal();
|
||||
} else {
|
||||
alert(I18n.getTranslation("localuser.noToken"));
|
||||
checkbox.setState(false);
|
||||
}
|
||||
} else {
|
||||
delete this.perminfo.applications[appId];
|
||||
this.userinfo.updateLocal();
|
||||
}
|
||||
});
|
||||
form.addButtonInput("", I18n.getTranslation("localuser.advancedBot"), () => {
|
||||
|
|
|
@ -107,8 +107,29 @@ export class Specialuser {
|
|||
this.json.localuserStore = e;
|
||||
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() {
|
||||
return this.json.localuserStore;
|
||||
type jsonParse = {
|
||||
[key: string | number]: any;
|
||||
};
|
||||
return this.proxySave(this.json.localuserStore) as {
|
||||
[key: string | number]: jsonParse;
|
||||
};
|
||||
}
|
||||
set id(e) {
|
||||
this.json.id = e;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue