1- let x = prompt ( 'Enter a text: ' ) ;
2- const name = x ;
31const logo = document . getElementById ( "logo" ) ;
42const intervals = new Map ( ) ;
3+ let userText = "" ;
54
6- // Create spans for each word and its characters
7- const words = name . match ( / ( \S + | \s ) / g) ;
8- words . forEach ( ( word ) => {
9- const wordSpan = document . createElement ( "span" ) ;
10- wordSpan . classList . add ( "word" ) ;
11-
12- word . split ( "" ) . forEach ( ( char , i ) => {
13- const span = document . createElement ( "span" ) ;
14- span . classList . add ( "char" ) ;
15- span . dataset . index = i ;
16- span . dataset . char = char ;
17- span . textContent = char ;
18- wordSpan . appendChild ( span ) ;
19- } ) ;
20-
21- // Add space after each word
22- const space = document . createElement ( "span" ) ;
23- space . textContent = " " ;
24- wordSpan . appendChild ( space ) ;
25-
26- logo . appendChild ( wordSpan ) ;
27- } ) ;
5+ // Prompt until valid input or cancel
6+ while ( ! userText ) {
7+ const input = prompt ( "Enter a text:" ) ;
8+ if ( input === null ) break ;
9+ if ( input . trim ( ) !== "" ) {
10+ userText = input ;
11+ }
12+ }
2813
14+ // Render logo if valid input
15+ if ( userText ) {
16+ renderLogo ( userText ) ;
17+ } else {
18+ logo . innerHTML = "<span style='opacity:0.5;'>No text entered</span>" ;
19+ }
2920
3021// Random character generator
3122function getRandomChar ( ) {
@@ -35,7 +26,7 @@ function getRandomChar() {
3526
3627// Start randomizing a character
3728function startRandomizing ( char ) {
38- if ( char . dataset . char === " " ) return ; // Skip spaces
29+ if ( char . dataset . char === " " ) return ;
3930 if ( intervals . has ( char ) ) return ;
4031
4132 const interval = setInterval ( ( ) => {
@@ -47,15 +38,44 @@ function startRandomizing(char) {
4738
4839// Stop randomizing and show actual letter
4940function stopRandomizing ( char ) {
50- if ( char . dataset . char === " " ) return ; // Skip spaces
41+ if ( char . dataset . char === " " ) return ;
5142 if ( intervals . has ( char ) ) {
5243 clearInterval ( intervals . get ( char ) ) ;
5344 intervals . delete ( char ) ;
5445 }
5546 char . textContent = char . dataset . char ;
5647}
5748
58- // Track cursor and update characters
49+ // Render logo from text
50+ function renderLogo ( text ) {
51+ logo . innerHTML = "" ;
52+ const words = text . match ( / ( \S + | \s ) / g) ; // preserves all spaces
53+
54+ words . forEach ( ( word ) => {
55+ const wordSpan = document . createElement ( "span" ) ;
56+ wordSpan . classList . add ( "word" ) ;
57+
58+ if ( word === " " ) {
59+ const space = document . createElement ( "span" ) ;
60+ space . classList . add ( "char" ) ;
61+ space . textContent = " " ;
62+ wordSpan . appendChild ( space ) ;
63+ } else {
64+ word . split ( "" ) . forEach ( ( char , i ) => {
65+ const span = document . createElement ( "span" ) ;
66+ span . classList . add ( "char" ) ;
67+ span . dataset . index = i ;
68+ span . dataset . char = char ;
69+ span . textContent = char ;
70+ wordSpan . appendChild ( span ) ;
71+ } ) ;
72+ }
73+
74+ logo . appendChild ( wordSpan ) ;
75+ } ) ;
76+ }
77+
78+ // Cursor tracking
5979document . addEventListener ( "mousemove" , ( e ) => {
6080 const chars = document . querySelectorAll ( ".char" ) ;
6181
@@ -68,3 +88,17 @@ document.addEventListener("mousemove", (e) => {
6888 }
6989 } ) ;
7090} ) ;
91+
92+ // Edit button
93+ document . getElementById ( "editBtn" ) . addEventListener ( "click" , ( ) => {
94+ const newText = prompt ( "Edit your text:" , userText ) ;
95+ if ( newText !== null && newText . trim ( ) !== "" ) {
96+ userText = newText ;
97+ renderLogo ( userText ) ;
98+ }
99+ } ) ;
100+
101+ // Refresh button
102+ document . getElementById ( "refreshBtn" ) . addEventListener ( "click" , ( ) => {
103+ location . reload ( ) ;
104+ } ) ;
0 commit comments