-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
randomization.mjs
88 lines (77 loc) · 3.09 KB
/
randomization.mjs
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
import pkg from './routes.mjs';
import { existsSync, readFileSync } from 'fs';
import { fileURLToPath } from 'node:url';
export { paintSource, preloaded404, tryReadFile };
const {
cookingInserts,
vegetables,
charRandom,
splashRandom,
cacheBustList,
VersionValue,
text404,
} = pkg;
/* Below are lots of function definitions used to obfuscate the website.
* This makes the website harder to properly categorize, as its source code
* changes with each time it is loaded.
*/
const randomListItem = (lis) => () => lis[(Math.random() * lis.length) | 0],
charset = /­|​|­|<wbr>/gi,
getRandomChar = randomListItem(charRandom),
insertCharset = (str) => str.replace(charset, getRandomChar),
getRandomSplash = randomListItem(splashRandom),
hutaoInsert = (str) => str.replaceAll('<!--HUTAOWOA-->', getRandomSplash),
versionInsert = (str) => str.replaceAll('<!-- VERSION -->', VersionValue),
getCookingText = () =>
`<span style="display:none" data-fact="${randomListItem(vegetables)()}">${randomListItem(cookingInserts)()}</span>`,
insertCooking = (str) =>
str.replaceAll(
'<!-- IMPORTANT-HUTAOCOOKINGINSERT-DONOTDELETE -->',
getCookingText
),
// This one isn't for obfuscation; it's just for dealing with cache issues.
cacheBusting = (str) => {
for (let item of Object.entries(cacheBustList))
str = str.replaceAll(item[0], item[1]);
return str;
},
// Apply the final obfuscation changes to an entire file.
paintSource = (str) =>
insertCharset(hutaoInsert(versionInsert(insertCooking(cacheBusting(str))))),
// Use this instead of text404 for a preloaded error page.
preloaded404 = paintSource(text404),
// Grab the text content of a file. Ensure the file is a string.
tryReadFile = (file, baseUrl) => {
file = fileURLToPath(new URL(file, baseUrl));
return existsSync(file + '')
? readFileSync(file + '', 'utf8')
: preloaded404;
};
/*
All of this is now old code.
The newer versions of these functions are directly above.
function randomListItem(lis) {
return lis[Math.floor(Math.random() * lis.length)];
}
function insertCharset(str) {
return str.replace(/­|​|­|<wbr>/g, function() { return randomListItem(charRandom); });
}
function hutaoInsert(str) {
return str.replace(/<!--HUTAOWOA-->/g, function() { return randomListItem(splashRandom); });
}
function insertCooking(str) {
return str.replace(/<!-- IMPORTANT-HUCOOKINGINSERT-DONOTDELETE -->/g, function() { return '<span style="display: none;" data-fact="' + randomListItem(vegetables) + '" data-type="' + randomListItem(vegetables) + '">' + randomListItem(cookingInserts) + '</span>'; }); // this needs to be inside a function, so that not every string is the same
}
function cacheBusting(str) {
for (var item of Object.entries(cacheBustList)) {
str = str.replace(new RegExp(item[0], "g"), item[1]);
}
return str;
}
export function paintSource(str) {
return insertCharset(hutaoInsert(insertCooking(cacheBusting(str))));
}
export function tryReadFile(file) {
return existsSync(file) ? readFileSync(file, 'utf8') : text404;
}
*/