Updated some functions to ES6 syntax and implemented the alternative to RegEx string replacement.

This commit is contained in:
00Fjongl 2024-07-07 01:48:14 -05:00
parent 093651c1eb
commit be3ad2ab58

View file

@ -25,6 +25,43 @@ const insertText = (lis, str, newText) => {
return str; return str;
}; };
const randomListItem = lis => lis[Math.random() * lis.length | 0];
const charset = ["­", "​", "­"];
const insertCharset = str => insertText(
charset,
str,
() => randomListItem(charRandom)
);
const hutaoInsert = str => insertText(
"<!--HUTAOWOA-->",
str,
() => randomListItem(splashRandom)
);
const insertCooking = str => insertText(
"<!-- IMPORTANT-HUTAOCOOKINGINSERT-DONOTDELETE -->",
str,
() => `<span style="display:none" data-fact="${randomListItem(vegetables)}">${randomListItem(cookingInserts)}</span>`
);
const cacheBusting = str => {
for (let item of Object.entries(cacheBustList))
str = insertText(item[0], str, item[1]);
return str;
};
export const paintSource = str => insertCharset(hutaoInsert(insertCooking(cacheBusting(str))));
export const tryReadFile = file => existsSync(file) ? readFileSync(file, "utf8") : text404;
/*
// All of this is now old code.
// The newer versions of these functions are directly above.
*/
/*
function randomListItem(lis) { function randomListItem(lis) {
return lis[Math.floor(Math.random() * lis.length)]; return lis[Math.floor(Math.random() * lis.length)];
} }
@ -54,4 +91,6 @@ export function paintSource(str) {
export function tryReadFile(file) { export function tryReadFile(file) {
return existsSync(file) ? readFileSync(file, 'utf8') : text404; return existsSync(file) ? readFileSync(file, 'utf8') : text404;
} }
*/