This commit is contained in:
legop3
2026-04-24 21:44:26 -04:00
parent f23a0e15c3
commit e54b8e34ab
10 changed files with 592 additions and 77 deletions
+52
View File
@@ -0,0 +1,52 @@
import { useEffect } from 'react';
import { useSessionSelector } from '../context/SessionContext.jsx';
function getRandomElement(elements) {
if (!elements || !elements.length) return null;
const idx = Math.floor(Math.random() * elements.length);
return elements[idx] || null;
}
function corruptDomOnce() {
if (typeof document === 'undefined' || !document.body) return;
const elements = document.body.getElementsByTagName('*');
if (!elements || elements.length < 2) return;
const sourceA = getRandomElement(elements);
const targetA = getRandomElement(elements);
const classA = sourceA?.classList?.[0] || null;
if (classA && targetA?.classList) {
try {
targetA.classList.add(classA);
} catch {
// Best-effort chaos; ignore invalid class token failures.
}
}
const sourceB = getRandomElement(elements);
const targetB = getRandomElement(elements);
const classB = sourceB?.classList?.[1] || null;
if (classB && targetB?.classList) {
try {
targetB.classList.add(classB);
} catch {
// Best-effort chaos; ignore invalid class token failures.
}
}
}
export default function DeterrenceChaos() {
const isDeterred = useSessionSelector((state) => Boolean(state.session?.moderation?.isDeterred));
useEffect(() => {
if (!isDeterred) return undefined;
const timer = window.setInterval(() => {
corruptDomOnce();
}, 1);
return () => {
window.clearInterval(timer);
};
}, [isDeterred]);
return null;
}