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

View file

@ -1,5 +1,6 @@
"use client"; "use client";
import { uwuifyDocument } from "@/lib/uwuify";
import { ThemeProvider, useTheme } from "next-themes"; import { ThemeProvider, useTheme } from "next-themes";
import { type ReactNode, useEffect } from "react"; import { type ReactNode, useEffect } from "react";
@ -27,10 +28,31 @@ function ThemeWatcher() {
return null; return null;
} }
function UwuWatcher() {
// Uwuify the whole page when ctrl + u is pressed
useEffect(() => {
function onKeyDown(event: KeyboardEvent) {
if (event.key === "u" && (event.metaKey || event.ctrlKey)) {
event.preventDefault();
uwuifyDocument();
}
}
window.addEventListener("keydown", onKeyDown);
return () => {
window.removeEventListener("keydown", onKeyDown);
};
}, []);
return null;
}
export function Providers({ children }: { children: ReactNode }) { export function Providers({ children }: { children: ReactNode }) {
return ( return (
<ThemeProvider attribute="class" disableTransitionOnChange={true}> <ThemeProvider attribute="class" disableTransitionOnChange={true}>
<ThemeWatcher /> <ThemeWatcher />
<UwuWatcher />
{children} {children}
</ThemeProvider> </ThemeProvider>
); );

View file

@ -39,6 +39,7 @@
"typescript": "^5.8.3", "typescript": "^5.8.3",
"unist-util-filter": "^5.0.1", "unist-util-filter": "^5.0.1",
"unist-util-visit": "^5.0.0", "unist-util-visit": "^5.0.0",
"uwuifier": "^4.2.2",
"zustand": "^5.0.3", "zustand": "^5.0.3",
}, },
"devDependencies": { "devDependencies": {
@ -835,6 +836,8 @@
"util-deprecate": ["util-deprecate@1.0.2", "", {}, "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="], "util-deprecate": ["util-deprecate@1.0.2", "", {}, "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="],
"uwuifier": ["uwuifier@4.2.2", "", {}, "sha512-Fhtj3Yg3rrDTEs+L1fqkgM3VYGJrP4U9GY+4fPdw08T5kzOB8NSosZnZfa5Zhv1Hh7NCpH5G6t1DIZyM1wPK1w=="],
"vfile": ["vfile@6.0.3", "", { "dependencies": { "@types/unist": "^3.0.0", "vfile-message": "^4.0.0" } }, "sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q=="], "vfile": ["vfile@6.0.3", "", { "dependencies": { "@types/unist": "^3.0.0", "vfile-message": "^4.0.0" } }, "sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q=="],
"vfile-message": ["vfile-message@4.0.2", "", { "dependencies": { "@types/unist": "^3.0.0", "unist-util-stringify-position": "^4.0.0" } }, "sha512-jRDZ1IMLttGj41KcZvlrYAaI3CfqpLpfpf+Mfig13viT6NKvRzWZ+lXz0Y5D60w6uJIBAOGq9mSHf0gktF0duw=="], "vfile-message": ["vfile-message@4.0.2", "", { "dependencies": { "@types/unist": "^3.0.0", "unist-util-stringify-position": "^4.0.0" } }, "sha512-jRDZ1IMLttGj41KcZvlrYAaI3CfqpLpfpf+Mfig13viT6NKvRzWZ+lXz0Y5D60w6uJIBAOGq9mSHf0gktF0duw=="],

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

View file

@ -46,6 +46,7 @@
"typescript": "^5.8.3", "typescript": "^5.8.3",
"unist-util-filter": "^5.0.1", "unist-util-filter": "^5.0.1",
"unist-util-visit": "^5.0.0", "unist-util-visit": "^5.0.0",
"uwuifier": "^4.2.2",
"zustand": "^5.0.3" "zustand": "^5.0.3"
}, },
"devDependencies": { "devDependencies": {