docs/lib/uwuify.ts

37 lines
719 B
TypeScript
Raw Normal View History

2025-04-05 03:10:36 +02:00
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;
}
}
};