22
33import { useEffect , useMemo , useState } from "react" ;
44
5- const TYPE_SPEED_MS = 42 ;
6- const DELETE_SPEED_MS = 22 ;
7- const HOLD_MS = 3676 ;
8- const BETWEEN_GREETING_MS = 280 ;
5+ const DEFAULT_TYPE_SPEED_MS = 42 ;
6+ const DEFAULT_DELETE_SPEED_MS = 22 ;
7+ const DEFAULT_HOLD_MS = 3676 ;
8+ const DEFAULT_BETWEEN_GREETING_MS = 280 ;
99
1010const GREETINGS = [
1111 ( name : string ) => `Hello, ${ name } !` ,
12+ ( name : string ) => `${ name } , your working is correct but the answer is wrong.` ,
1213 ( name : string ) => `Eat more curry, ${ name } !` ,
1314 ( name : string ) => `Subscribe to Let's Think Critically, ${ name } !` ,
15+ ( name : string ) => `${ name } , have you tried turning your brain off and on again?` ,
1416 ( name : string ) => `Welcome back, ${ name } .` ,
1517 ( name : string ) => `Wassup :), ${ name } .` ,
16- ( name : string ) => `Good to see you, ${ name } .` ,
17- ( name : string ) => `Make me proud, ${ name } .` ,
1818 ( name : string ) => `Be Culver Kwan, ${ name } .` ,
1919 ( name : string ) => `Time to lock in, ${ name } .` ,
20- ( name : string ) => `Be Marcoroni :3, ${ name } .` ,
2120 ( name : string ) => `Marcoroni is typing..., ${ name } .` ,
2221 ( name : string ) => `Search Marco The Dog, ${ name } .` ,
2322 ( name : string ) => `Be more ORZ, ${ name } .` ,
2423 ( name : string ) => `Solve these problems if you're not gay, ${ name } .` ,
2524 ( name : string ) => `${ name } ! Stay determined!` ,
26- ( ) => `Nature is written in mathematical language.` ,
27- ( ) => `In mathematics, you don’t understand things. You just get used to them.` ,
2825 ( name : string ) => `${ name } , you forgot a ± somewhere.` ,
2926 ( name : string ) => `${ name } , you look like a trapezium.` ,
27+ ( ) => `Just cancel the dx's. Trust me.` ,
28+ ( ) => `Proof left as an exercise to the reader.` ,
29+ ( ) => `Step 1: Draw a circle. Step 2: ???. Step 3: Proof complete.` ,
3030 ( ) => `The Riemann Hypothesis has been solved!` ,
3131 ( ) => `I still remember the thrill of solving my first integral.` ,
32+ ( name : string ) => `${ name } divided by 0. Error.` ,
3233 ( ) => `Numbers don't lie.` ,
3334 ( ) => `Is it always true? Sometimes true? Or never true?` ,
3435 ( name : string ) => `${ name } , WAKE UP!` ,
35- ( ) => `lim h->0 f(x+h) - f(x) / h` ,
36+ ( ) => `sin(x) = x. QED.` ,
37+ ( ) => `It is trivially obvious that 0 = 1. QED.` ,
3638 ( name : string ) => `${ name } " or 1 = 1 --` ,
3739 ( ) => `Take pi = 3` ,
3840 ( ) => `Eat. Sleep. Math. Repeat.` ,
41+ ( name : string ) => `Initialising ${ name } ... please wait... still waiting...stillllllll waiting...` ,
3942] ;
4043
4144const getRandomGreetingIndex = ( exclude ?: number ) => {
@@ -52,18 +55,57 @@ function GreetingTyper({ name }: { name: string }) {
5255 const [ greetingIndex , setGreetingIndex ] = useState ( ( ) => getRandomGreetingIndex ( ) ) ;
5356 const [ charIndex , setCharIndex ] = useState ( 0 ) ;
5457 const [ isDeleting , setIsDeleting ] = useState ( false ) ;
58+ const [ speeds , setSpeeds ] = useState ( {
59+ typeSpeed : DEFAULT_TYPE_SPEED_MS ,
60+ deleteSpeed : DEFAULT_DELETE_SPEED_MS ,
61+ holdMs : DEFAULT_HOLD_MS ,
62+ betweenMs : DEFAULT_BETWEEN_GREETING_MS ,
63+ } ) ;
64+
65+ useEffect ( ( ) => {
66+ try {
67+ const stored = localStorage . getItem ( "mo-typewriter-settings" ) ;
68+ if ( stored ) {
69+ const parsed = JSON . parse ( stored ) ;
70+ setSpeeds ( {
71+ typeSpeed : Math . max ( 10 , Math . min ( 500 , Number ( parsed . typeSpeed ) || DEFAULT_TYPE_SPEED_MS ) ) ,
72+ deleteSpeed : Math . max ( 10 , Math . min ( 500 , Number ( parsed . deleteSpeed ) || DEFAULT_DELETE_SPEED_MS ) ) ,
73+ holdMs : Math . max ( 500 , Math . min ( 15000 , Number ( parsed . holdMs ) || DEFAULT_HOLD_MS ) ) ,
74+ betweenMs : Math . max ( 100 , Math . min ( 5000 , Number ( parsed . betweenMs ) || DEFAULT_BETWEEN_GREETING_MS ) ) ,
75+ } ) ;
76+ }
77+ } catch { }
78+
79+ const handleStorage = ( ) => {
80+ try {
81+ const stored = localStorage . getItem ( "mo-typewriter-settings" ) ;
82+ if ( stored ) {
83+ const parsed = JSON . parse ( stored ) ;
84+ setSpeeds ( {
85+ typeSpeed : Math . max ( 10 , Math . min ( 500 , Number ( parsed . typeSpeed ) || DEFAULT_TYPE_SPEED_MS ) ) ,
86+ deleteSpeed : Math . max ( 10 , Math . min ( 500 , Number ( parsed . deleteSpeed ) || DEFAULT_DELETE_SPEED_MS ) ) ,
87+ holdMs : Math . max ( 500 , Math . min ( 15000 , Number ( parsed . holdMs ) || DEFAULT_HOLD_MS ) ) ,
88+ betweenMs : Math . max ( 100 , Math . min ( 5000 , Number ( parsed . betweenMs ) || DEFAULT_BETWEEN_GREETING_MS ) ) ,
89+ } ) ;
90+ }
91+ } catch { }
92+ } ;
93+
94+ window . addEventListener ( "storage" , handleStorage ) ;
95+ return ( ) => window . removeEventListener ( "storage" , handleStorage ) ;
96+ } , [ ] ) ;
5597
5698 const activeGreeting = useMemo ( ( ) => GREETINGS [ greetingIndex ] ( name ) , [ greetingIndex , name ] ) ;
5799
58100 useEffect ( ( ) => {
59- let delay = isDeleting ? DELETE_SPEED_MS : TYPE_SPEED_MS ;
101+ let delay = isDeleting ? speeds . deleteSpeed : speeds . typeSpeed ;
60102
61103 if ( ! isDeleting && charIndex === activeGreeting . length ) {
62- delay = HOLD_MS ;
104+ delay = speeds . holdMs ;
63105 }
64106
65107 if ( isDeleting && charIndex === 0 ) {
66- delay = BETWEEN_GREETING_MS ;
108+ delay = speeds . betweenMs ;
67109 }
68110
69111 const timer = window . setTimeout ( ( ) => {
0 commit comments