mirror of
https://github.com/versia-pub/docs.git
synced 2025-12-06 22:38:19 +01:00
37 lines
719 B
TypeScript
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;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
};
|