mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-17 13:30:01 -04:00
Replace method turns out to be faster than the custom function, at least for simple strings and simple regular expressions.
This commit is contained in:
parent
c76cf7df1a
commit
106bd07aa6
3 changed files with 24 additions and 51 deletions
|
@ -1,60 +1,35 @@
|
||||||
import pkg from "./routes.mjs";
|
import pkg from "./routes.mjs";
|
||||||
import { existsSync, readFileSync } from "fs";
|
import { existsSync, readFileSync } from "fs";
|
||||||
|
export { paintSource, tryReadFile };
|
||||||
const {
|
const {
|
||||||
cookingInserts,
|
cookingInserts,
|
||||||
vegetables,
|
vegetables,
|
||||||
charRandom,
|
charRandom,
|
||||||
splashRandom,
|
splashRandom,
|
||||||
cacheBustList,
|
cacheBustList,
|
||||||
text404,
|
text404,
|
||||||
} = pkg;
|
} = pkg;
|
||||||
export { insertText, paintSource, tryReadFile };
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Try this instead of the .replace method. Might be more performant.
|
|
||||||
// Will edit str by replacing all matches of lis with newText.
|
|
||||||
// Usage: insertText(['<Example1>', '<Example2>'],
|
|
||||||
// '<Example1> Big Giant Paragraph <Example2> Smol Paragraph',
|
|
||||||
// stringOrFunctionToGenerateNewText);
|
|
||||||
*/
|
|
||||||
const insertText = (lis, str, newText) => {
|
|
||||||
let position;
|
|
||||||
|
|
||||||
// The lis argument should be a list of strings containing placeholders.
|
|
||||||
// Ensure lis is formatted as a list, and loop through each of the
|
|
||||||
// placeholder strings.
|
|
||||||
for (let placeholder of [].concat(lis)) {
|
|
||||||
// Find all matches of a placeholder string and insert new text there.
|
|
||||||
while ((position = str.indexOf(placeholder)) != -1)
|
|
||||||
str =
|
|
||||||
str.slice(0, position) +
|
|
||||||
(typeof newText == "function" ? newText() : newText) +
|
|
||||||
str.slice(position + placeholder.length);
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Below are lots of function definitions used to obfuscate the website.
|
// Below are lots of function definitions used to obfuscate the website.
|
||||||
// This makes the website harder to properly categorize, as its source code
|
// This makes the website harder to properly categorize, as its source code
|
||||||
// changes with each time it is loaded.
|
// changes with each time it is loaded.
|
||||||
const randomListItem = (lis) => () => lis[(Math.random() * lis.length) | 0],
|
const randomListItem = (lis) => () => lis[(Math.random() * lis.length) | 0],
|
||||||
charset = ["­", "​", "­", "<wbr>"],
|
charset = /­|​|­|<wbr>/gi,
|
||||||
getRandomChar = randomListItem(charRandom),
|
getRandomChar = randomListItem(charRandom),
|
||||||
insertCharset = (str) => insertText(charset, str, getRandomChar),
|
insertCharset = (str) => str.replace(charset, getRandomChar),
|
||||||
getRandomSplash = randomListItem(splashRandom),
|
getRandomSplash = randomListItem(splashRandom),
|
||||||
hutaoInsert = (str) => insertText("<!--HUTAOWOA-->", str, getRandomSplash),
|
hutaoInsert = (str) => str.replaceAll("<!--HUTAOWOA-->", getRandomSplash),
|
||||||
getCookingText = () =>
|
getCookingText = () =>
|
||||||
`<span style="display:none" data-fact="${randomListItem(vegetables)()}">${randomListItem(cookingInserts)()}</span>`,
|
`<span style="display:none" data-fact="${randomListItem(vegetables)()}">${randomListItem(cookingInserts)()}</span>`,
|
||||||
insertCooking = (str) =>
|
insertCooking = (str) =>
|
||||||
insertText(
|
str.replaceAll(
|
||||||
"<!-- IMPORTANT-HUTAOCOOKINGINSERT-DONOTDELETE -->",
|
"<!-- IMPORTANT-HUTAOCOOKINGINSERT-DONOTDELETE -->",
|
||||||
str,
|
|
||||||
getCookingText
|
getCookingText
|
||||||
),
|
),
|
||||||
// This one isn't for obfuscation; it's just for dealing with cache issues.
|
// This one isn't for obfuscation; it's just for dealing with cache issues.
|
||||||
cacheBusting = (str) => {
|
cacheBusting = (str) => {
|
||||||
for (let item of Object.entries(cacheBustList))
|
for (let item of Object.entries(cacheBustList))
|
||||||
str = insertText(item[0], str, item[1]);
|
str = str.replaceAll(item[0], item[1]);
|
||||||
return str;
|
return str;
|
||||||
},
|
},
|
||||||
// Apply the final obfuscation changes to an entire file.
|
// Apply the final obfuscation changes to an entire file.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { insertText, tryReadFile } from "./randomization.mjs";
|
import { tryReadFile } from "./randomization.mjs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
export { loadTemplates as default };
|
export { loadTemplates as default };
|
||||||
|
|
||||||
|
@ -22,17 +22,15 @@ const header = tryReadFile(
|
||||||
settings = tryReadFile(
|
settings = tryReadFile(
|
||||||
path.normalize(__dirname + "/views/pages/misc/deobf/settings.html")
|
path.normalize(__dirname + "/views/pages/misc/deobf/settings.html")
|
||||||
),
|
),
|
||||||
loadTemplates = (str) => {
|
loadTemplates = (str) =>
|
||||||
str = insertText("<!--HEADER-->", str, header);
|
str.replace("<!--HEADER-->", header)
|
||||||
str = insertText("<!--FOOTER-->", str, footer);
|
.replace("<!--FOOTER-->", footer)
|
||||||
|
|
||||||
// Used only on docs.html
|
// Used only on docs.html
|
||||||
str = insertText("<!--DOCS-->", str, documentation);
|
.replace("<!--DOCS-->", documentation)
|
||||||
// Used only on faq.html
|
// Used only on faq.html
|
||||||
str = insertText("<!--FAQ-->", str, faq);
|
.replace("<!--FAQ-->", faq)
|
||||||
// Used only on terms.html
|
// Used only on terms.html
|
||||||
str = insertText("<!--TOS-->", str, terms);
|
.replace("<!--TOS-->", str, terms)
|
||||||
// Used only on csel.html
|
// Used only on header.html
|
||||||
str = insertText("<!--SETTINGS-->", str, settings);
|
.replace("<!--SETTINGS-->", str, settings);
|
||||||
return str;
|
|
||||||
};
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
/* Card Shimmer Mouse Follow Script
|
/* Card Shimmer Mouse Follow Script
|
||||||
/* ----------------------------------------------- */
|
/* ----------------------------------------------- */
|
||||||
|
|
||||||
// Function declarations
|
// Function declarations
|
||||||
// Track the cursor position with respect to the top left of the card.
|
// Track the cursor position with respect to the top left of the card.
|
||||||
// The "this" keyword gets the element that invoked the event listener.
|
// The "this" keyword gets the element that invoked the event listener.
|
||||||
const handleMouseMove = element => {
|
const handleMouseMove = element => {
|
||||||
|
@ -26,7 +26,7 @@ handleMouseLeave = element => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Query and add event listeners
|
// Query and add event listeners
|
||||||
const shimmerEffects = document.querySelectorAll(".box-card");
|
const shimmerEffects = document.querySelectorAll(".box-card");
|
||||||
|
|
||||||
// Attach CSS variables, mouse-x and mouse-y, to elements that will be
|
// Attach CSS variables, mouse-x and mouse-y, to elements that will be
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue