mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-27 03:25:44 +02:00
prettify, sorry for the big ass commit
This commit is contained in:
@@ -1,53 +1,53 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
function replace(str: string, i: number, char: string): string {
|
||||
return str.substring(0, i) + char + str.substring(i + 1);
|
||||
return str.substring(0, i) + char + str.substring(i + 1);
|
||||
}
|
||||
|
||||
interface IProps {
|
||||
content: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
function randomize(char: string): string {
|
||||
const randFrom = (str: string): string => str[Math.floor(Math.random()*str.length)];
|
||||
const classes = [
|
||||
"abcdefghijklmnopqrstuvwxyz",
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
"1234567890",
|
||||
" _",
|
||||
"()[]{}<>",
|
||||
];
|
||||
const other = `!@#$%^&*()_+|\\';"/.,?\`~`;
|
||||
const randFrom = (str: string): string =>
|
||||
str[Math.floor(Math.random() * str.length)];
|
||||
const classes = [
|
||||
"abcdefghijklmnopqrstuvwxyz",
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
"1234567890",
|
||||
" _",
|
||||
"()[]{}<>",
|
||||
];
|
||||
const other = `!@#$%^&*()_+|\\';"/.,?\`~`;
|
||||
|
||||
for(const c of classes) {
|
||||
if (c.includes(char)) return randFrom(c);
|
||||
}
|
||||
for (const c of classes) {
|
||||
if (c.includes(char)) return randFrom(c);
|
||||
}
|
||||
|
||||
return randFrom(other);
|
||||
return randFrom(other);
|
||||
}
|
||||
|
||||
export function CorruptableText(props: IProps): JSX.Element {
|
||||
const [content, setContent] = useState(props.content);
|
||||
const [content, setContent] = useState(props.content);
|
||||
|
||||
useEffect(() => {
|
||||
let counter = 5;
|
||||
const id = setInterval(() => {
|
||||
counter--;
|
||||
if (counter > 0)
|
||||
return;
|
||||
counter = Math.random() * 5;
|
||||
const index = Math.random() * content.length;
|
||||
const letter = content.charAt(index);
|
||||
setContent(replace(content, index, randomize(letter)));
|
||||
setTimeout(() => {
|
||||
setContent(content);
|
||||
}, 50);
|
||||
}, 100);
|
||||
useEffect(() => {
|
||||
let counter = 5;
|
||||
const id = setInterval(() => {
|
||||
counter--;
|
||||
if (counter > 0) return;
|
||||
counter = Math.random() * 5;
|
||||
const index = Math.random() * content.length;
|
||||
const letter = content.charAt(index);
|
||||
setContent(replace(content, index, randomize(letter)));
|
||||
setTimeout(() => {
|
||||
setContent(content);
|
||||
}, 50);
|
||||
}, 100);
|
||||
|
||||
return () => {
|
||||
clearInterval(id);
|
||||
};
|
||||
}, []);
|
||||
return () => {
|
||||
clearInterval(id);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return <span>{content}</span>
|
||||
}
|
||||
return <span>{content}</span>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user