This repository has been archived by the owner on Jun 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflse.js
351 lines (328 loc) · 10.7 KB
/
flse.js
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/*
FLSE 2.0.4 240921
Developed and engineered for the sites of tomorrow.
Stable Channel
*/
const flsedetec = { v: "2.0.3", channel: "stable" };
const settings = {};
var imports = {};
try {
flsestrings;
} catch (error) {
var flsestrings = {};
}
flseBootstrap();
function flseBootstrap() {
settings["longLan"] = navigator.language.replace("-", "_");
if (settings["longLan"].includes("_")) {
settings["shortLan"] = settings["longLan"].split("_")[0];
}
const bodyRemovalCSS = document.createElement("style");
bodyRemovalCSS.innerHTML = `
body, flseimport, flsedefine {
display: none;
}
`;
bodyRemovalCSS.setAttribute("id", "flseBodyDry");
document.body.appendChild(bodyRemovalCSS);
settings["cssVar"] = true;
gatherImports(1);
}
function gatherImports(ft = 0) {
var ebimports = document.getElementsByTagName("flseimport");
var ebdefine = document.getElementsByTagName("flsedefine");
window["importStats"] = {
max: ebimports.length + ebdefine.length,
current: 0,
};
for (const importDec of ebimports) {
if (
importDec.getAttribute("registered") == "registered" ||
importDec.getAttribute("registered") == "registering" ||
importDec.getAttribute("registered") == "failed"
) {
continue;
} else {
const importID = btoa(Math.random());
const type = importDec.getAttribute("type");
const name = importDec.getAttribute("name");
const src = importDec.getAttribute("src");
importDec.setAttribute("ranID", importID);
importDec.setAttribute("registered", "registering");
if (type == null) {
console.error(
`FLSE: The import for "${importID}" could not be completed.\nThere is no type.`
);
importDec.setAttribute("registered", "failed");
continue;
}
if (src == null) {
console.error(
`FLSE: The import for "${importID}" could not be completed.\nThere is no source location.`
);
importDec.setAttribute("registered", "failed");
continue;
}
if (type == "component") {
fetch(src).then((response) => {
var statusCode = response.status.toString();
if (statusCode.startsWith("2")) {
response.text().then((data) => {
imports[name] = {
type: type,
contents: data,
};
importDec.setAttribute("registered", "registered");
incrementGotCounter(ft);
});
} else {
console.error(
`FLSE: The import for "${importID}" could not be completed.\nThe server responded with ${statusCode}.`
);
importDec.setAttribute("registered", "failed");
incrementGotCounter(ft);
}
});
}
if (type == "components") {
fetch(src).then((response) => {
var statusCode = response.status.toString();
if (statusCode.startsWith("2")) {
response.text().then((data) => {
try {
var dataParsed = JSON.parse(data);
for (const arrElement of dataParsed) {
imports[arrElement["tag"]] = {
type: "component",
contents: arrElement["value"],
};
}
importDec.setAttribute("registered", "registered");
} catch (error) {
importDec.setAttribute("registered", "failed");
console.error(
`FLSE: The import for "${importID}" could not be completed.\nThe source file is not encoded correctly.`
);
}
incrementGotCounter(ft);
});
} else {
console.error(
`FLSE: The import for "${importID}" could not be completed.\nThe server responded with ${statusCode}.`
);
importDec.setAttribute("registered", "failed");
incrementGotCounter(ft);
}
});
}
if (type == "module") {
fetch(src).then((response) => {
var statusCode = response.status.toString();
if (statusCode.startsWith("2")) {
response.text().then((data) => {
checkModule(data, name);
imports[name] = {
type: type,
contents: new Function("element", data),
};
importDec.setAttribute("registered", "registered");
incrementGotCounter(ft);
});
} else {
console.error(
`FLSE: The import for "${importID}" could not be completed.\nThe server responded with ${statusCode}.`
);
importDec.setAttribute("registered", "failed");
}
});
}
}
}
for (const importDec of ebdefine) {
if (
importDec.getAttribute("registered") == "registered" ||
importDec.getAttribute("registered") == "registering" ||
importDec.getAttribute("registered") == "failed"
) {
continue;
} else {
const importID = btoa(Math.random());
const type = importDec.getAttribute("type");
const name = importDec.getAttribute("name");
importDec.setAttribute("ranID", importID);
if (type == null) {
console.error(
`FLSE: The import for "${importID}" could not be completed.\nThere is no type.`
);
importDec.setAttribute("registered", "failed");
continue;
}
if (type == "component") {
imports[name] = {
type: type,
contents: importDec.innerHTML,
};
importDec.setAttribute("registered", "registered");
incrementGotCounter(ft);
}
if (type == "module") {
imports[name] = {
type: type,
contents: new Function("element", importDec.innerHTML),
};
importDec.setAttribute("registered", "registered");
incrementGotCounter(ft);
}
}
}
if (window["importStats"]["max"] == 0 || ft == 0) {
incrementGotCounter(ft, false);
}
}
function incrementGotCounter(ft = 0, increment = true) {
if (increment == true) {
window["importStats"]["current"] += 1;
}
if (
window["importStats"]["current"] == window["importStats"]["max"] ||
ft == 0
) {
languages(ft);
}
}
function placeLang() {}
function languages(ft = 0) {
var legacyLanElem = document.querySelectorAll("[flsestring]");
for (const item of legacyLanElem) {
var targetLan = item.getAttribute("flsestring");
if (item.getAttribute("registered") != "registered") {
item.setAttribute("registered", "registered");
if (flsestrings[targetLan]["default"] != null) {
item.innerHTML = flsestrings[targetLan]["default"];
}
if (flsestrings[targetLan][settings["longLan"]] != null) {
item.innerHTML = flsestrings[targetLan][settings["longLan"]];
}
if (settings["shortLan"] != null) {
if (flsestrings[targetLan][settings["shortLan"]] != null) {
item.innerHTML = flsestrings[targetLan][settings["shortLan"]];
}
}
}
}
placeElems(ft);
}
function placeElems(ft = 0) {
var everyElem = document.getElementsByTagName("*");
window["everyElemStats"] = {
max: everyElem.length,
current: 1,
};
for (const elem of everyElem) {
setTimeout(() => {
const tagName = elem.tagName.toLowerCase();
if (tagName in imports) {
if (imports[tagName]["type"] == "module") {
elem.outerHTML = imports[tagName]["contents"](elem);
}
if (imports[tagName]["type"] == "component") {
elem.outerHTML = imports[tagName]["contents"];
}
}
if (settings["cssVar"] == true) {
incrementElemCounter(1);
} else {
incrementElemCounter(ft);
}
}, 0);
}
if (window["everyElemStats"]["max"] == 0) {
incrementElemCounter(ft, false);
}
}
function incrementElemCounter(ft = 0, increment = true) {
if (increment == true) {
window["everyElemStats"]["current"] += 1;
}
if (
window["everyElemStats"]["current"] == window["everyElemStats"]["max"] ||
ft == 0
) {
if (ft == 1) {
document.getElementById("flseBodyDry").innerHTML = `
flseimport, flsedefine {
display: none;
transition: none;
animation: none;
}
`;
addTriggers(ft);
}
}
}
function addTriggers(ft) {
settings["cssVar"] = false;
setInterval(() => {
try {
flseUpdate();
} catch (e) {}
if (ft == 1) {
settings["lastHTML"] = document.body.innerHTML;
ft = 0;
try {
flseLoadcall();
} catch (e) {}
placeElems(0);
} else {
if (settings["lastHTML"] != document.body.innerHTML) {
gatherImports(0);
}
settings["lastHTML"] = document.body.innerHTML;
}
}, 10);
}
function checkModule(moduleData, moduleName) {
var safe = 1;
const dataLower = moduleData.toLowerCase();
if (dataLower.includes("eval")) {
console.warn(
`FLSE: The module "${moduleName}" may contain potentially harmful code that may pose security risks to this page and any data transferred between it.
Details: Real-time translation (eval).`
);
safe = 0;
}
if (
dataLower.includes(".getelementbyid") ||
dataLower.includes(".getelementsbyclassname") ||
dataLower.includes(".getelementsbytagname")
) {
console.warn(
`FLSE: The module "${moduleName}" contains a direct reference to an element that could potentially be used to phish data outbound this page.
Details: Target elements via IDs, class names, tag names. (getElem)`
);
safe = 0;
}
if (
(dataLower.includes("script") && dataLower.includes("createelement")) ||
dataLower.includes("<script>") ||
dataLower.includes("</script>")
) {
console.warn(
`FLSE: The module "${moduleName}" contains an injection to inline or external scripts that could be used to potentially phish data outbound this page.
Details: Script Injection`
);
safe = 0;
}
if (dataLower.includes("fetch") || dataLower.includes("xmlhttprequest")) {
console.warn(
`FLSE: The module "${moduleName}" may make requests to external sources, which could be used to phish data outbound this page.
Details: External network requests. (fetch, XMLHttpRequest)`
);
safe = 0;
}
if (safe == 0) {
console.error(
"FLSE: There are critical messages being displayed in the Warnings log."
);
}
}