CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
ProdigyPNP

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: ProdigyPNP/ProdigyMathGameHacking
Path: blob/master/cheatGUI/src/class/Toggler.ts
Views: 723
1
import Hack from "./Hack";
2
3
4
5
6
export default class Toggler extends Hack {
7
enabled?: () => unknown;
8
disabled?: () => unknown;
9
constructor(
10
public parent: HTMLDivElement,
11
name?: string,
12
description?: string
13
) {
14
super(parent, name, description);
15
this.element.setAttribute("status", "false");
16
this.setClick(async () => {
17
this.status = !this.status;
18
if (this.status) {
19
localStorage.setItem(this.name, "true");
20
await this.enabled?.();
21
} else {
22
localStorage.setItem(this.name, "false");
23
await this.disabled?.();
24
}
25
});
26
}
27
28
get status() {
29
return JSON.parse(this.element.getAttribute("status")!) as boolean;
30
}
31
32
set status(val) {
33
this.element.setAttribute("status", val.toString());
34
}
35
36
setEnabled(event: () => unknown) {
37
this.enabled = event;
38
if (localStorage.getItem(this.name) === "true") {
39
this.element.click();
40
}
41
return this;
42
}
43
44
setDisabled(event: () => unknown) {
45
this.disabled = event;
46
return this;
47
}
48
}
49
50