docs/lib/uwuify.ts
Jesse Wierzbinski be79c569a1
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
feat: Introduce uwu mode
2025-04-05 03:10:36 +02:00

37 lines
719 B
TypeScript

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;
}
}
};