-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.js
More file actions
184 lines (156 loc) · 5.27 KB
/
loader.js
File metadata and controls
184 lines (156 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
const LOADER = {
baseStyles: [
"window.css",
"ui.css",
"tip.css",
"button.css",
"textbox.css",
"checkbox.css",
"radio.css",
"range.css"
],
baseScripts: [
"ui.js",
"window.js"
],
primaryScripts: [
"tabs.js",
"console.js",
"ipbox.js",
"terminal.js",
"wasm_exec.js"
],
secondaryScripts: [
"about.js",
"personalize.js",
"locateip.js",
"maclookup.js",
"passwordgen.js",
"encoder.js",
"netcalc.js",
"keyboardtester.js",
"mictester.js",
"cameratester.js",
"screencapture.js",
"serial.js",
"chess/chess.js"
],
Initialize: ()=> {
let count = 0;
const total = LOADER.baseStyles.length + LOADER.baseScripts.length + LOADER.primaryScripts.length + LOADER.secondaryScripts.length;
const callbackHandle = (status, filename)=> {
loadingbar.style.width = 100 * ++count / total + "%";
if (LOADER.baseStyles.length + LOADER.baseScripts.length === count) { //load primary
for (let i = 0; i < LOADER.primaryScripts.length; i++)
LOADER.LoadScript(LOADER.primaryScripts[i], callbackHandle);
}
else if (LOADER.baseStyles.length + LOADER.baseScripts.length + LOADER.primaryScripts.length === count) { //load secondary
UI.Initialize();
for (let i = 0; i < LOADER.secondaryScripts.length; i++)
LOADER.LoadScript(LOADER.secondaryScripts[i], callbackHandle);
}
else if (count === total) { //all done
setTimeout(()=> {
loadingcontainer.style.filter = "opacity(0)";
setTimeout(()=> container.removeChild(loadingcontainer), 200);
setTimeout(()=> LOADER.RestoreSession(), 250); //restore previous session
}, 200);
}
};
for (let i = 0; i < LOADER.baseStyles.length; i++)
LOADER.LoadStyle(LOADER.baseStyles[i], callbackHandle);
for (let i = 0; i < LOADER.baseScripts.length; i++)
LOADER.LoadScript(LOADER.baseScripts[i], callbackHandle);
},
LoadStyle: (filename, callback)=> {
if (document.head.querySelectorAll(`link[href$='${filename}']`).length > 0) {
callback("exists", filename);
return;
}
const cssLink = document.createElement("link");
cssLink.rel = "stylesheet";
cssLink.href = filename;
document.head.appendChild(cssLink);
cssLink.onload = ()=> callback("ok", filename);
cssLink.onerror = ()=> callback("error", filename);
},
LoadScript: (filename, callback)=> {
if (document.head.querySelectorAll(`script[src$='${filename}']`).length > 0) {
callback("exists", filename);
return;
}
const script = document.createElement("script");
script.setAttribute("defer", true);
script.src = filename;
document.body.appendChild(script);
script.onload = ()=> callback("ok", filename);
script.onerror = ()=> callback("error", filename);
},
StoreSession: ()=> {
let session = [];
if (localStorage.getItem("restore_session") === "true")
for (let i = 0; i < WIN.array.length; i++)
session.push({
class: WIN.array[i].constructor.name,
params: WIN.array[i].params,
isMaximized: WIN.array[i].isMaximized,
isMinimized: WIN.array[i].isMinimized,
position: WIN.array[i].position,
left: WIN.array[i].win.style.left,
top: WIN.array[i].win.style.top,
width: WIN.array[i].win.style.width,
height: WIN.array[i].win.style.height
});
localStorage.setItem("session", JSON.stringify(session));
return session;
},
RestoreSession: ()=> {
fragment = window.location.href.substring(window.location.href.indexOf("#") + 1, window.location.href.length);
if (fragment === "passgen") {
new PassGen();
return;
}
let session = localStorage.getItem("session") ? JSON.parse(localStorage.getItem("session")) : {};
if (localStorage.getItem("restore_session") != "true") return;
if (session == null || session.length == 0) return;
for (let i = 0; i < session.length; i++) {
let win = LOADER.Invoke(session[i]);
if (win) {
if (session[i].isMaximized) win.Toggle();
if (session[i].isMinimized) win.Minimize();
win.position = session[i].position;
if (!WIN.always_maxed) {
win.win.style.left = session[i].left;
win.win.style.top = session[i].top;
win.win.style.width = session[i].width;
win.win.style.height = session[i].height;
}
}
}
},
Invoke: (command)=> {
switch (command.class) {
case "LocateIp" : return new LocateIp(command.params);
case "MacLookup" : return new MacLookup(command.params);
case "PassGen" : return new PassGen(command.params);
case "Encoder" : return new Encoder(command.params);
case "NetCalc" : return new NetCalc(command.params);
case "KeyboardTester" : return new KeyboardTester(command.params);
case "MicTester" : return new MicTester(command.params);
case "CameraTester" : return new CameraTester(command.params);
case "ScreenCapture" : return new ScreenCapture(command.params);
case "SerialRS232" : return new SerialRS232(command.params);
case "Chess" : return new Chess();
case "About" : return new About(command.params);
case "Personalize" : return new Personalize(command.params);
}
},
HttpErrorHandler: statusCode=> {
switch (statusCode) {
case 401: throw new Error("Unauthorized user or authorization expired");
case 403: throw new Error("Insufficient permissions");
default: throw new Error(`Server responded with: ${statusCode}`);
}
}
};
LOADER.Initialize();