feat: Introduce uwu mode
Some checks failed
Check Types / tests (push) Failing after 41s
CodeQL / Analyze (javascript) (push) Failing after 52s
Lint & Format / tests (push) Successful in 27s
Mirror to Codeberg / Mirror (push) Failing after 0s

This commit is contained in:
Jesse Wierzbinski 2025-04-05 03:10:36 +02:00
parent 5026e59d17
commit be79c569a1
No known key found for this signature in database
4 changed files with 62 additions and 0 deletions

36
lib/uwuify.ts Normal file
View file

@ -0,0 +1,36 @@
import Uwuifier from "uwuifier";
const uwuifier = new Uwuifier();
const getAllDOMTextNodes = (): Node[] => {
const walker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_TEXT,
null,
);
const nodes: Node[] = [];
while (true) {
const newNode = walker.nextNode();
if (!newNode) {
break;
}
nodes.push(newNode);
}
return nodes;
};
export const uwuifyDocument = (): void => {
const textNodes = getAllDOMTextNodes();
for (const node of textNodes) {
if (node.nodeValue) {
const newText = uwuifier.uwuifySentence(node.nodeValue);
node.nodeValue = newText;
}
}
};