mirror of
https://github.com/versia-pub/docs.git
synced 2026-03-13 02:49:16 +01:00
feat: ✨ Introduce uwu mode
This commit is contained in:
parent
5026e59d17
commit
be79c569a1
4 changed files with 62 additions and 0 deletions
36
lib/uwuify.ts
Normal file
36
lib/uwuify.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue