forked from QuiteAFancyEmerald/Holy-Unblocker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandomization.mjs
34 lines (27 loc) · 1.27 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
import pkg from './routes.mjs';
import { existsSync, readFileSync } from 'fs';
const { cookingInserts, vegetables, charRandom, splashRandom, cacheBustList, text404 } = pkg;
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;
}