import pkg from "./routes.mjs"; import { existsSync, readFileSync } from "fs"; export { paintSource, tryReadFile }; const { cookingInserts, vegetables, charRandom, splashRandom, cacheBustList, 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 = /­|​|­|/gi, getRandomChar = randomListItem(charRandom), insertCharset = (str) => str.replace(charset, getRandomChar), getRandomSplash = randomListItem(splashRandom), hutaoInsert = (str) => str.replaceAll("", getRandomSplash), getCookingText = () => `${randomListItem(cookingInserts)()}`, insertCooking = (str) => str.replaceAll( "", 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(insertCooking(cacheBusting(str)))), // Grab the text content of a file. Ensure the file is a string. 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) { return lis[Math.floor(Math.random() * lis.length)]; } function insertCharset(str) { return str.replace(/­|​|­|/g, function() { return randomListItem(charRandom); }); } function hutaoInsert(str) { return str.replace(//g, function() { return randomListItem(splashRandom); }); } function insertCooking(str) { return str.replace(//g, function() { return '' + randomListItem(cookingInserts) + ''; }); // 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; } */